I was wondering how to use code syntax highlighter inside wordpress.com blog. So far I have used multiple highlight plug-ins for my locally hosted blogs but this wordpress.com one gave me real pain. Problem that I faced was wordpress.com won’t let me add any javascript to the post content. That’s a right and noble move and I appreciate that. But that also been the main reason behind my problem and I wasn’t able to use highlighted code snippet like the following one:

<?php
function test($val)
{
    if(isarray($val)){
        foreach($val as $v){
            echo 'value is '.$v.'<br />';
        }
    }
}
?>

So I searched more and finally I found a solution. Actually WordPress.com is providing a template keyword to fascilitate syntax highlighting more safely and securely. To get the support, you will have to write something like this



your code here

[/ sourcecode]

Please omit the space after the ‘/’ of the closing sourcecode tag.

This technique support multiple language syntax and those are

  • bash
  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • shell
  • sql
  • vb
  • xml

They are using the famous Syntax Highlighter plugins written by Alex Gorbatchev. They are just making it accessible in a more secure way.

Advertisements