I've got the following class declaration:

class stachethemes_ec_main extends stachethemes\event_calendar\stachethemes_main_template {

and the following function with the action hooks:

public function add_event_tab($slug, $title, $icon, $content = "", $file = false) {

        add_action('stachethemes_ec_add_event_tab', function() use($slug, $title, $icon) {
          if ($slug != "woocommerce") :
            echo "<li data-tab='stec-layout-event-inner-{$slug}'><i class='{$icon}'></i><p>{$title}</p></li>";

        add_action('stachethemes_ec_add_event_tab_content', function() use($slug, $content, $file) {

I want to remove the stachethemes_ec_add_event_tab_content action hook with the following remove_action:

function custom_stachethemes_tab_content(){
  remove_action('stachethemes_ec_add_event_tab_content',array('stachethemes_ec_main', 'add_event_tab'));

Am I doing anything wrong, because it's not working?

I have also tried with the following approach:

add_action('stachethemes_ec_add_event_tab_content','custom_stachethemes_tab_content', 20);
function custom_stachethemes_tab_content(){
  global $stachethemes;
  $stachethemes = stachethemes_ec_main::get_instance();
  remove_all_actions('stachethemes_ec_add_event_tab_content',array($stachethemes, 'add_event_tab'));

but is neither working!

  • you cannot remove a annonymous function with remove_action. but you can remove all hook of a action with remove_all_actions codex.wordpress.org/Function_Reference/remove_all_actions – mmm May 1 '17 at 14:20
  • This is my last approach: add_action('stachethemes_ec_add_event_tab_content','custom_stachethemes_tab_content',20); function custom_stachethemes_tab_content(){ global $stachethemes; $stachethemes = stachethemes_ec_main::get_instance(); remove_all_actions('stachethemes_ec_add_event_tab_content',array($stachethemes, 'add_event_tab')); } and it's stil not working. – deyan4 May 1 '17 at 14:23

Since you are not specifying a priority to your actions, they will be executed in the order they are encountered. So your remove_action may very well be executed after the actions tied to the same hook have already been executed. You could solve this by attaching a higher priority to the action that does the removal like this:


Beware also that remove_action does not remove the hook itself. It just removes the specified actions bound to that hook. If another action is tied to that hook later on, it will be executed.

  • But my action has to be executed before the action hook I'm removing and I need a lower priority (lower than 10, because it's by default), right? – deyan4 May 1 '17 at 14:14
  • Lower priority corresponds to earlier execution. So if you use a lower priority, you will be removing the action first and then adding it again, leading to it being executed. That's why you need a higher priority. Hooking is not the same as executing. Hooking is just determining the order in which stuff will be executed later on. – cjbj May 1 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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