Highlight Code Blocks in WordPress CodeUnit 20 DEC 2009

wordpress-logoIf your blog features a lot of code blocks or snippets, then it might be a good idea to consider displaying them in a manner that separates the code from the post text in terms of style and at the same time, go ahead and line number and colourize the code itself.

One fantastic plugin that has been developed to this end is Ryan McGeary’s WP-Syntax that utilizes the GeSHIi syntax highlighter engine in order to highlight any text placed within a specially designated block.

A large number of coding languages are supported by GeSHi and making use of the system to separate your code out of your text is as simple as placing it between <pre> tags. For example, to highlight PHP code you would place your code within a section cordoned off by a <pre lang=”php”> </pre> tag, resulting in this:

echo 'hello world!';

If for instance you want your code block numbered, simply make use of the line= attribute, for example <pre lang=”php” line=”1″>:

echo 'hello world!';

You can customise the colours use, you can deal with escaped quotes and you can start the number sequence from any number you want to, making WP-Syntax a pretty handy little ‘fella after all!

Related Link: http://wordpress.org/extend/plugins/wp-syntax/

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.