1

I am trying to remove the action hooks added by SEO ultimate plugin for some pages. The way it is added in the plugin's class is

    //Hook to output all <head> code i changed the priority to 2
    add_action('wp_head', array(&$this, 'template_head'), 2);

The SEO plugin creates a global variable like this

global $seo_ultimate;
    $seo_ultimate =& new SEO_Ultimate(__FILE__);

In my plugin, i try removing it by

add_action('wp_head',array($this, 'remove_seo_header'),1);

    }
    function remove_seo_header() {

         remove_action('wp_head', array($seo_ultimate,'template_head'));
}

But it does not remove the action. Can anyone point out where am I wrong?

1

You have to use the same priority, and you need access to the global variable:

function remove_seo_header() {

    remove_action(
        'wp_head', 
        array( $GLOBALS['seo_ultimate'], 'template_head' ), 2 
    );
}
|improve this answer|||||
0

You can also foreach through the registered hooks like this:

function remove_filter_in_class( $tag, $function_to_remove, $priority, $class ) {
    if ( isset( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
        foreach ( $GLOBALS['wp_filter'][ $tag ][ $priority ] as $key => $function ) {
            if ( is_array( $function['function'] )
                && $function_to_remove === array_pop( $function['function'] )
                && $class === get_class( array_pop( $function['function'] ) )
            ) {
                return remove_filter( $tag, $key, $priority );
            }
        }
    }
}

Source: https://gist.github.com/lgedeon/7806513f47b6466fc2cb

|improve this answer|||||

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.