shBrushPhp.js shBrushJScript.js shBrushSql.js shBrushXml.js ...
How to use Google Syntax Highlighter (GSH) in WordPress?
WordPress plugin was originally written by Peter Ryan and you can find the source at WordPress Plugin for Google Syntax Highlighter page. After plugin activation I analysed the HTML produced by Google Syntax Highlighter plugin and here is the result: one CSS in the <head> section and all possible brushes (a lot of them) at the page bottom. Even in the post without any program code to highlight, all brushes will be loaded anyway. So I decided to make plugin modification with the following objectives:
- load only needed brushes
- skip brushes loading if WordPress post doesn’t contain any program code
To reduce brush list immediately, find and edit google_syntax_highlighter.php from the plugins directory. Remove brushes you will never need. In my example it looks like:
gsh_brush -> Php gsh_brush -> JScript
Here goes modified google_syntax_highlighter.php code:
Brush loading is moved to the head section of the HTML page. Plugin has two hooked functions and one function for getting values from the Custom fields. If you apply this modification, you will have option to create brush list per post. I will stop here, but you can go even further and automate all this process without need to fill the Custom fields. For example, you can modify PHP function to search for all <pre name=”code” language=”PHP|JScript|Xml|…”> tags and automatically include found brushes. This method would certainly add some server load because PHP engine will have to search entire post before sending page to the client.