I've a self installed wordpres blog full of Python snippets and I'd like to have them highlighted (source code colored). I tried to install a couple of plugins like wp-syntax and Jquery.Syntax but they require me to edit all my posts adding some attrs to the pre tags.
How can I hack into the plugins or wordpress in other to apply the plugins to all the pre tags?
You can create a simple plugin that will register a "filter". This filter will apply to all your posts :
function enhance_pre_tag_filter($content){
$content = preg_replace( '/<pre>/', '<pre python_tags>', $content );
return $content;
}
foreach(array('the_content','the_title','comment_text') as $filter)
add_filter($filter, 'enhance_pre_tag_filter',9);
I think you will first need to check whether you are installing a theme or a plugin. Sometimes when you install a .zip
file of a theme, it goes in as a plugin. This can cause this error.
I would recommend to install a plugin such as Prismatic. It's free to use and very simple for highlighting code in WordPress posts and pages.
Once you have the plugin installed and activated, then set it to use one of the libraries from the plugin settings.
Then just simply do a database Find and Replace to add class="language-python"
to all of your <pre>
tags. Now you should see all of your Python code will be perfectly highlighted. Alternatively you could also just manually go and add that class to all your <pre>
tags.