Syntax Highlighter plugin for WordPress-MU

For some time now I was looking for a Syntax Highlighter plugin that will work good with WordPress-MU out of the mu-plugins directory. Since I could not find one I decided to modify an existing plugin. I chose the SyntaxHighlighter plugin by Erik Range. This plugin is actually based on code provided by Alex Gorbatchev.

I had to change it quite a bit since I removed the user backend, changed a few hooks and most important made sure that the Java Scripts required by the plugin will be loaded only when there is some code in the post and not for every page loaded. This issue is very important for high volume WPMU sites.

The Syntax Highlighter plugin for WordPress-MU supports the following programming languages:

  • Cpp
  • CSharp
  • Css
  • Delphi
  • Java
  • JScript
  • Php
  • Python
  • Ruby
  • Sql
  • Vb
  • Xml

Known issue: for some reason the plugin works on post view only and not on the home page. will try to fix it soon.

Download: wpmu-syntax-highlighter.zip (beta)

Installation: extract and place in the mu-plugins directory.

Usage: [ source:language] source code comes here [/source]

language is one of the programming languages listed above.

Important: Please note to NOT use a whitespace in the [ source:language] command like shown in Usage and Example below. If you copy & paste it, don’t forget to remove the space.

Example: entering the following code

[ source:php]
// Re-insert source as (formatted) textarea
foreach( $theSources[2] as $sourceID => $sourceBlock ) {
$theBrush =
$theSources[1][$sourceID].$optionString;
$thePost = str_replace(
”{sourceID:{$sourceID}}”,
);
}
[/source]

Will result with this code:

// Re-insert source as (formatted) textarea
foreach( $theSources[2] as $sourceID => $sourceBlock ) {
$theBrush =
$theSources[1][$sourceID].$optionString;
$thePost = str_replace(
”{sourceID:{$sourceID}}”,
);
}

Did you find this post interesting? Please subscribe to my feed.

Comments 5