remove_action in a theme

I’m using a theme that gets updated pretty frequently. For this, it has added a custom.php file to include modifications. Now, in this theme, under the functions.php, the developer has included his own meta section which is added using the following function:

add_action('wp_head', 'theme_metas');

I want to let my SEO plugin manage this, so I tried adding this into the custom.php:

Read More
remove_action('wp_head', 'theme_metas', 15);

I even tried altering the priority higher and lower than 10 (which is default) but the metas are still showing. Can someone shed some light please?

Related posts

Leave a Reply

2 comments

  1. Your remove_action has to have a priority matching the priority used in add_action.

    Important: To remove a hook, the $function_to_remove and $priority
    arguments must match when the hook was added. This goes for both
    filters and actions. No warning will be given on removal failure.

    http://codex.wordpress.org/Function_Reference/remove_action

    In you case, it looks like remove_action('wp_head', 'theme_metas'); should work, but you may be having trouble because of how and when your custom.php file loads.

  2. For removing an action the priority has to be the same priority as was used when adding the action. in your case it should be

    remove_action('wp_head', 'theme_metas');
    

    or

    remove_action('wp_head', 'theme_metas',10);
    

    The fine detail to remember is that remove of an action can be done only after the action was already added. Actions are simply stored in an array and all remove_action does is to nullify the entry. If remove_action is called before add_action the end result will be that the remove will effectively do nothing.

    Therefor you should call remove_action only when you are sure that the add_action was called and for most actions a good bet is to hook with highest priority on the hook in question.

    In your case

    add_action('wp_head','wpse86994_remove_action',1); // prioroty of 1, but can be anything higher (lower number) then the priority of the action
    
    function wpse86994_remove_action() {
      remove_action('wp_head', 'theme_metas');
    }