views:

41

answers:

1

Hi,

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?

A: 

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);
Benoit Courtine
How I ensure to run it before the other plugin? The other one use 0 as last parameter for add_filter.
Juanjo Conti
I tried to activate that as a plugin and got a "The plugin does not have a valid header." message.
Juanjo Conti
To ensure this filter is executed before, it must have a lower priority. If the other plugin filter has a 0 (highest) priority, you have to change it.The code I gave you is only the main part of the plugin. To be valid, a WP plugin must have a valid header (PHP comments). See the WordPress codex (article http://codex.wordpress.org/Writing_a_Plugin) for the details.
Benoit Courtine