Code Syntax Highlighting In WordPress

Karol Krizka @ March 11, 2008

Blogging, Programming

screenshot-2.png

From time to time I post random code on this blog and I want it to be displayed in a legible manner. This is quite impossible with the default WordPress setup, because all code will just be displayed like random text. Luckily there is the wp-syntax plugin, which will detect the code and apply different styles automatically (using GeSHi) to it so it looks just like in your editor.

I recommend that you read the official wp-syntax usage notes, as they can simply your life by quite a lot. Here are a few notes of my own.

  • If your code contains both HTML and PHP, set the language to PHP (you can’t do both). It should also highlight the HTML tags.
  • Apply the styles suggested in the usage notes. They take care of text overflow problems and distinguishing post text from code.
  • Omit the line=”1″ argument if you do not want line numbering.
  • Do not replace < with < and so on. wp-syntax will do this conversion for you.

For now I’ll leave you with an example of wp-syntax in action:

for($i=0; $i&lt;100; $i++){
  echo "Hello world!";
}

Did you enjoy this post? Then why not subscribe to my RSS feed or subscribe by e-mail? Also check out the many other FREE ways to appreciate a blogger.


Related Posts

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
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> <pre lang="" line=""> in your comment.

Feed