Adding Third Party Brushes to SyntaxHighlighter Evolved in WordPress

SyntaxHighlighter Evolved is one of the most popular WordPress plugins for adding highlighted code to your posts and pages. It comes with support for most languages, but there are some missing like batch files (CMD, BAT) and Inno Setup scripts (ISS).

There are different ways of adding third party brushes to this plugin but the easiest is to write a plugin that registers new brushes to SyntaxHighlighter Evolved. To do this we only need a brush file and create the actual plugin file that will register it.

This is a comprehensive list of brushes you can download and use. Once you have the brushes you need, copy them to a folder that will have the name of your plugin. In my case the folder is called syntaxhighlighter-brushes. Open your text editor (my favorite is Notepad++) to create an empty PHP file in this folder. My file is called as the folder, syntaxhighlighter-brushes.php.

Folder Structure

Here are the contents of the plugin file I wrote. Copy and paste them into yours.

[php]<?php
/*
Plugin Name: SyntaxHighlighter Evolved – Brushes
Description: Third party brushes for SyntaxHighlighter Evolved
Author: Ruben Alamina
Version: 1.0
Author URI: https://rubenalamina.mx/
*/

// SyntaxHighlighter doesn’t do anything until early in the "init" hook.
add_action(‘init’,’syntaxhighlighter_regscript’);

// Tell SyntaxHighlighter about the new brushes.
add_filter(‘syntaxhighlighter_brushes’,’syntaxhighlighter_addlang’);

// Register brushes with SyntaxHighlighter.
function syntaxhighlighter_regscript() {
wp_register_script(‘syntaxhighlighter-brush-batch’, plugins_url(‘syntaxhighlighter-brushes/shBrushBatch.js’), array(‘syntaxhighlighter-core’),’1.0′);
wp_register_script(‘syntaxhighlighter-brush-inno’, plugins_url(‘syntaxhighlighter-brushes/shBrushInno.js’), array(‘syntaxhighlighter-core’),’1.0′);
}
// Alternative names for the brushes. You can use more than one name for every type.
function syntaxhighlighter_addlang($brushes) {
$brushes[‘bat’] = ‘batch’;
$brushes[‘cmd’] = ‘batch’;
$brushes[‘iss’] = ‘inno’;

return $brushes;
}
?>[/php]

I already commented some lines to give you a better idea. Modify this file to use the name of your brush file(s). Once you’re done, upload the folder to the plugins folder of your WordPress installation and activate in the Admin Dashboard like any other plugin.

You now will able to use the shortcodes for bat, cmd and iss or any other brushes you have added. If you need these brushes, here the links to download them.

[button color=”color” size=”small” url=”https://www.dropbox.com/s/tp0ypft9myjflgq/shBrushBatch.js” icon=”file” iconcolor=”white” target=”_blank” ] Batch Brush [/button] [button color=”color” size=”small” url=”https://www.dropbox.com/s/kfn0ugeb82pmm5e/shBrushInno.js” icon=”file” iconcolor=”white” target=”_blank” ] Inno Brush [/button]