Download link at the bottom.
Yesterdays research has pointed me one important issue – the WP-syntax plugin was taking way too long to process the homepage. And it wasn’t only the WP-Syntax but also other syntax-highlighting plugins including WP-GeSHi-highlight and Better WordPress Syntax Highlighter.
From few tested I found that WP-GeSHi-Highlight has the best performance but still – it wasn’t so great.
I was thinking – is there any way to speed up this plugin (or at least minimize the “damage”)?
The plugin itself is very well commented and is very simple, this is the simplified flow of the script:
- Plugin init
- Loop through posts to display and parse full text looking for <pre lang=”> tag
- If found – mark the place with unique identifier
- Replace every unique identifier with the GeSHi output
What if one of the posts doesn’t contain <pre lang=”> tag? The plugin still has to parse whole text to look for it. This doesn’t sound good if you want to highlight code only in a fraction of your posts.
After done with the profiling I decided it is worth to modify the plugin.
The new feature works in a very simple way, go to your dashboard and under Settings->WP-GeSHi-Highlight you can set the tag with which posts will be parsed.
The last thing you need to do is to tag all the posts with the code snippets and the plugin will do all the rest for you.
Keep your load times low and your wordpress will love you forever!