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?
Your
remove_action
has to have a priority matching the priority used inadd_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 yourcustom.php
file loads.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
or
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. Ifremove_action
is called beforeadd_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