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:

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...

  • how about remove_action( 'wp_head', 'custom_function'); ?
    – Bainternet
    Apr 3, 2012 at 12:19
  • Do you know the name of custom_function? I mean, is it always the same and always bound to wp_head with the same priority?
    – hakre
    Apr 3, 2012 at 12:50
  • Sorry, I made some more changes to code example. Yes, I tried to use remove_action() and hook to wp_head, but no success. I also tried to debug actions and change priorities. Now custom_function() is bound to some_hook and from wp_head is called setup_theme() function which contains add_shortcode().
    – user3316
    Apr 3, 2012 at 15:24

4 Answers 4


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:

  • Thank you for your answer! By removing this shortcode, I will also remove the whole test_shortcode() function which is very huge and sometimes updated by theme authors. Then I would have to add new shortcode with the same function (except add_action part). But the original function can be changed during theme update and so there could be problems. And that is why I wanted only remove small part of it - add_action() function.
    – user3316
    Apr 3, 2012 at 15:10

Have you considered remove_action( 'some_hook', 'custom_function');?

  • Yes, but it does not work, because you cannot remove action which does not exist yet. Action custom_function() is running when add_shortcode() is applied.
    – user3316
    Apr 3, 2012 at 17:46
  • I didn't mean use it before, I meant use it after it fires but before page load. If you're not able to remove it, and you're dead set on getting rid of it, then comment out the line, make a note somewhere, and recomment it out whenever an update rolls out. That seems the simpler solution. Keep in mind that cutting out that function may break something else - you have been warned.
    – SickHippie
    Apr 3, 2012 at 19:29

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!


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;

Seems like it does the job ;-)

  • Sorry, but it was not helpful. You are checking existence of some shortcode, but I wanted to remove action from related shortcode function (see my working solution).
    – user3316
    Aug 9, 2012 at 10:47
  • How does this relate to the question asked?
    – kaiser
    Oct 10, 2012 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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