Displaying code in a Wordpress post by Lloyd Armbrust
There are many ways to display code in a WP post. You could wrap your code with the pre tag:
<pre>
Or, the xmp tag will tell your browser to ignore its rendering engine:
<xmp>
But if you’re trying to display PHP or JS, things will still not render correctly.
On this weblog, we use a WordPress plug-in called SyntaxHighlighter Plus. It was adapted for WordPress by people like Fred Wu and Matt Mullenweg from Google’s SyntaxHighlighter JavaScript package by Alex Gorbatchev.
- Download it here: http://wordpress.org/extend/plugins/syntaxhighlighter-plus/
- Upload and install it to your WP plug-ins directory.
- Then wrap your code with: [sourcecode language='php']..[/sourcecode]
Make sure to match the “language” attribute with the language of the code you’re wrapping:
- cpp
- csharp
- css
- delphi
- html
- java
- jscript
- php
- python
- ruby
- sql
- vb
- xml
And that’s it, it should work like this:
<?php echo "Your plug-in is working!" ?>
September 30th, 2008 at 9:41 am
sweet!
September 30th, 2008 at 9:42 am
I know. It is.
September 30th, 2008 at 10:45 pm
I was wondering what that was.
October 25th, 2009 at 8:51 pm
“Displaying code in a Wordpress post ” is really nice post. Thank you for share.