Code Highligter for WordPress

By Akbar

After upgrading my WordPress Application, I thought to also search for some good code highlighter plug-in for WordPress too. Apparently, there are couple of interesting one, but after quick review, I diceded to go with the Google Code Prettify for wordpress

The plug-in setup wasy nice and easy. The only thing which I didn’t like much was that to make the code highlight you also need to insert the correct attribute i.e. class=”prettryprint” in your code tag. I know, I know, the plug-in does a great job and it’s just one attribute to add, but the main problem, prbaobly just my own problem, is that I have to remember the exact attribute value I have to add after few days and I am very bad at this.

So what I did, I searched for the WordPress WYSIWYG Editor code which insert the “CODE” tag. I found that one in the “quicktags.js” (under the path “wp-includesjs”) and changed the “<code>” string with “<code class=’prettyprint’>” (have to do it at two places). Did a refresh and now when I insert the Code tag from HTML view mode, it will insert the correct attribute tag too.  Here is a quick test:

Printf("Hello World!");

This is a dirty way of doing this as this may go away with my next WordPress upgrade, but that is way I am blogging about it so that I can quickly read and apply this again as and when required.

Tags: , ,