jQuery.Syntax WordPress Plugin Fixes

jQuery.Syntax WordPress Plugin Fixes

Searching a lightweight syntax highlighting plugin for WordPress, I found jQuery.Syntax, a plugin based on the jQuery plugin jQuery.Syntax. Both, the plugin for jQuery and that for WordPress are developed by Samuel Williams, but it seems as if he stopped his efforts for the WordPress plugin, because it got its last update in 2011 and produces PHP and WordPress errors on modern WordPress installations. This is easy to fix, you only have to change small stuff in a few lines.

At first quote the callback function in the preg_replace_callback in lines 37 and 38.

$content = preg_replace_callback('/<(pre)(.*?)>(.*?)<\/pre>/imsu','jq_syntax_htmlentities', $content);
$content = preg_replace_callback('/<(code)(.*?)>(.*?)<\/code>/imsu','jq_syntax_htmlentities', $content);

Then in line 47 comment out the explicit loading of jquery and adapt the loading of the jquery.syntax code.

// wp_enqueue_script('jquery');
wp_enqueue_script('jquery.syntax', $path . 'jquery-syntax/jquery.syntax.min.js', array('jquery'), '3.0', true );

At last in line 68 change the way, the scripts are loaded into the header.

add_action('wp_enqueue_scripts', 'jq_syntax_loaded');

Schreibe einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>