Oct 29 2009

Displaying code in WordPress posts

I’ve conquered it!
Somewhere along the line of this blog my code snippets quit displaying properly. I’ve spent a bit of time trying to get it working in the past and just gave up. But alas!
I kept trying to use:

[sourcecode language="xml"]  [/sourcecode] 

and it caused a lot of bad words to come out if my mouth because it never worked. I read that it doesn’t work with all themes so I tried a handful.

More bad words.

THEN I saw fine print somewhere that that only works on wordpress.com installed blogs. If you have yours hosted elsewhere it’s a different beast. You must install Google Syntax Highlighter for WordPress

The usage is a bit different, so check this doc before you start typing away.

ALSO NOTE that you can’t just type

<pre name="code" class="xml">
... some code here ...
</pre>

into the ‘Visual’ tab in the wordpress post page. You must switch to ‘HTML’ view or it won’t work.

Ahhh, now I get to go through some old posts and fix the displayed code!

Post to Twitter