Highlight Code Blocks in WordPress

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!';
die();

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

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Software & Websites and tagged , , , , . Bookmark the permalink.