Archive

Posts Tagged ‘Source code’

Highlighting Code when Blogging

November 14th, 2008

When you want to display code, i.e. syntax of some programming language like PHP, C, Java or whatever on your blog you could just copy and past it. This doesn’t look very nice though and is most likely not enjoyable for your readers. A better approach would be to use the <pre></pre> tag which means that the included content is preformatted and which looks quite good with WordPress for example.

But there is even a more elegant alternative: use one of the freely available syntax highlighers around. For WordPress e.g. there is this great plugin called Syntax Highlighter. Getting this to work is really easy:

  • Download the plugin
  • Extract the content of the archive and place it in your wp-content/plugins folder
  • Activate the plugin in your WordPress administration
  • Highlight code by using: [source code language='css']code here[/source code] (without the blanks between source and code!)
  • Caution: change the language setting to your appropriate requirements (e.g. mysql, java, php, etc.). You will find a list of supported languages at the plugin link from above.
  • That’s it - it should work. If it doesn’t work (which happened to me…) read the FAQ where it says to make sure that your theme has the <?php wp_footer(); ?> line somewhere.

If you are wondering how this line of code would look like with the Synatx Highlighter… well, tattaaaa:

<?php wp_footer(); ?>

Blogging , , , ,