Tag Archives: code syntax

Highlight Your PHP Code Syntax with the WordPress Plugin, SyntaxHighlighter Evolved! CodeUnit 06 JAN 2012

A website like this one involves the posting of a lot of code snippets and examples in a variety of development languages. Because code often looks a lot like a plain old bunch of textual gibberish, the ability to syntax-highlight the entry immediately makes it recognizable and thus useful to a programmer reading the entry.

WordPress.com has a useful feature built into it where it can automatically syntax-highlight code when placed within special shortcode markers, based on work by Alex Gorbatchev. Plugin author Viper007Bond together with the official Automattic company have taken this a little further, wrapping it up in a WordPress plugin form and releasing it to the public at large as SyntaxHighlighter Evolved!

Featuring support for a wide variety of languages, highlighting your code syntax is as easy as writing

[ php ]code[ /php ]

The plugin takes care of html entities and all that sort of encoding stuff, meaning that you don’t have to manually change your snippet in order for WordPress to properly display it! In addition, there are plenty of options you can employ within the shortcode blocks in order to extend the display functionality, like adding highlighted rows, line numbers, etc.

Powerful (and really useful) stuff! :)

Related Link: http://wordpress.org/extend/plugins/syntaxhighlighter

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!';
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/