Apr 01 2008

Playing With Wordpress Code Highlighter Plugin

by David Jeffries under Misc at 12:00 pm

I just installed this code highlighter plugin for Wordpress, and it's really neat. It allows you to post any code you want between <pre> tags, and it will highlight/colour the text properly based on what language you tell it.

Language Support

This plugin uses GeSHi as a fontifier engine, and it supports many, many different languages. From applescript to java to sql this engine supports pretty much every popular language.

Line Numbers

You can also show the code with line numbers by adding lineno="{starting number}" to the pre tag like so: <pre lang="php" lineno="5"> which would start it on line 5. This does, however, make it difficult to copy and paste code because the line numbers are also copied.

PHP example (<pre lang="php">)

<?php
  class Test{
    public function Test(){
      echo "Test instantiated!";
    }
  }
?>

Java example (<pre lang="java">)

class Test{
  public static void main(String[] args){
    Test t = new Test();
  }
  public Test(){
    System.out.println("Test instantiated!");
  }
}

This is one of the most useful plugins I've ever seen, I love it. It makes posting code so much nicer and makes it way easier to read. Now I just have to update all my old posts that have code in them... For more information and to download, go to ideathinking.com

Like this post? Subscribe to the full RSS feed.

Comments RSS feed | Trackback URI

1 Comment »

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post