Remove action from shortcode

There is add_action() function inside function which is callback for add_shortcode(). Any idea how to remove this action with the help of custom plugin? Should I hook to any action which is called later then add_shortcode() function? I do not want to removing and re-adding shortcode, because there is huge function beyond it.

Simple example:

Read More
function test_shortcode() {
  ... other code ...
  add_action( 'some_hook', 'custom_function');
  ... other code ...
}

add_action( 'wp_head', 'setup_theme' );
function setup_theme() {
  ... other code...
  add_shortcode( 'test', 'test_shortcode' );
  ... other code ...
}

I need to remove custom_function() from this shortcode.

Thank you for your help…

Related posts

Leave a Reply

4 comments

  1. I do not want to removing and re-adding shortcode, because there is huge function beyond it.

    This might not answer your question, but the size of the shortcode function itself does not make much of a difference for removing and re-adding. Short or long functions take the same time here.

    So don’t hinder yourself removing the shortcode (remove_shortcode) because of the size of the function (huge), just remove it if you want to remove it, regardless how big it is:

    remove_shortcode('test');
    
  2. OK, I found a way. Function add_shortcode is called for the_content filter with priority 11 (after wpautop). So, to remove custom_function() has to be done with the help of this filter (also with priority 11). Solution?

    add_filter( 'the_content', 'unhook_custom_function', 11 );
    function unhook_custom_function( $content ) {
      remove_action( 'some_hook', 'custom_function' );
      return $content;
    }
    

    Works well for me. Thank you all for ideas!

  3. Found the code bellow on https://gist.github.com/1887242

    if ( ! function_exists( 'shortcode_exists' ) ) :
    /**
     * Check if a shortcode is registered in WordPress.
     *
     * Examples: shortcode_exists( 'caption' ) - will return true.
     *           shortcode_exists( 'blah' )    - will return false.
     */
    function shortcode_exists( $shortcode = false ) {
        global $shortcode_tags;
    
        if ( ! $shortcode )
            return false;
    
        if ( array_key_exists( $shortcode, $shortcode_tags ) )
            return true;
    
        return false;
    }
    endif;
    

    Seems like it does the job 😉