Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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?

share|improve this question
    
Nice Answers you received! Consider using a functionality plugin or a Must Use plugin. –  brasofilo Feb 15 '13 at 8:09
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
It doesn't work. I have added other functions in the custom.php and they load just find. This is the only code that is not overriding the add_action function. Any other suggestion? Globally define it or something perhaps? Thanks a lot for your kind assistance nevertheless. –  Aftab Feb 15 '13 at 7:15
    
You were right! The custom.php was being called BEFORE the add_action which is why it was not overriding it. Thanks a lot sir. –  Aftab Feb 15 '13 at 7:46
add comment

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');
}
share|improve this answer
    
None of them seems to work. How is priority considered? Is a lower integer considered higher priority or is it the other way round? Thanks a lot for your kind assistance nevertheless. –  Aftab Feb 15 '13 at 7:17
    
priority doesn't specify the priority of the remove but the priority of the action to be removed. Your problem might be that you are trying to remove the action before it was added, will update the answer for that –  Mark Kaplun Feb 15 '13 at 7:24
    
Thanks mark. That was helpful! I checked the functions source code and apparently the custom.php was being "require_once"-ed before the add_filter code which was causing that issue. I've reported it to the theme developer too. You were very helpful. –  Aftab Feb 15 '13 at 7:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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