2

I am using a plugin called "syntaxhighlighter".

I know not to ask for plugin specific questions but rather how to filter out action added to the wp_head / wp_footer conditionally...

This is a part of the plugin script:

// Outputting SyntaxHighlighter's JS and CSS
add_action( 'wp_head', array( $this, 'output_header_placeholder' ), 15 );
add_action( 'wp_footer', array( $this, 'maybe_output_scripts' ), 15 );

Now, i would like to add a filter that says:

if(is_home() || is_category()) {
   // REMOVE THOSE SCRIPS
}

.
I dont want to change that plugin code becouse i would have
to remmember to do it again when it updates...

How can i filter those actions out when needed?

4

You can try this (untested):

add_action( 'wp_head', 
   function(){
       // your conditions:
       if( is_home() || is_category() )
       {
           // access the global SyntaxHighlighter object instantiated at 'init'.
           global $SyntaxHighlighter;

           // remove your action hooks:
           remove_action( 'wp_head',    
                           array( $SyntaxHighlighter, 'output_header_placeholder' ),
                           15 );
           remove_action( 'wp_footer', 
                           array( $SyntaxHighlighter, 'maybe_output_scripts' ),
                           15 );
       }
   }
);

to remove these action hooks conditionally with template tags. We use the wp_head action with the default priority 10.

You can use other hooks but they must fire earlier than wp_head with priority 15 and after the $SyntaxHighlighter object creation via the init hook.

You must also make sure that your template tags, you want to use in your conditional checks, are available in the hook you choose.

3
  • intresting ;) going to test it. Thanks mate. would be back soon – Sagive SEO Mar 2 '14 at 15:24
  • Works like a charm... should have known this alone ;) thanks for your help – Sagive SEO Mar 2 '14 at 16:05
  • Happy to hear it worked for you, cheers. – birgire Mar 2 '14 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.