I’ve been meaning to post some sample code for a while, and I always wanted to have a nice WordPress plugin to perform syntax highlighting of code. A cursory search of the WordPress website brought up this page, which lists a bunch of syntax highlighting pluging. However, it appears to be a bit outdated, and many of the plugins are no longer supported, don’t work with WordPress 2.x, or their websites have simply disappeared. Some of the other plugins are too specific and only handle PHP code, etc.

However, the iG:Syntax Hiliter plugin completely fits the bill. It uses the popular and powerful GeSHI Syntax Highlighter, which is also embedded in several Wiki syntax highlighting plugins that I’ve used. Installation is simple as usual for WordPress plugins: Just download the plugin and copy it to the “plugins” folder. It uses tags of the form <pre>[language name]…[/language name]</pre> and supports most popular languages, including Ruby (the support for which was actually added by the plugin author).

The plugin also adds a nice options page in the WordPress admin interface, which allows configuration of many details, including colors, whether to display line numbers, the name of the language, whether to add a plaintext option, and more.

Here are some samples:

[ruby] class Foo attr_reader: @bar

def initialize(bar) @bar = bar end

def do_stuff puts “Bar: #{bar}” end end [/ruby]

[java] public class Foo { String bar;

public Foo(String bar) { this.bar = bar; }

public doStuff() { System.out.println(“Bar: “ + bar); } } [/java]

[sql] SELECT People.* FROM People, Cars WHERE People.car_id = Cars.id AND Cars.manufacturer = ‘honda’ [/sql]