Code Syntax Highlighting In WordPress

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<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.
My name is Karol Krizka, and I am a undergraduate student at SFU where I study physics and computer science. In my free time, I write simple applications and play with my PSP.
No comments yet.