I am trying to remove a theme action for an elegant-themes theme using a child theme.. This works when I remove action after add_action code anywhere in the parent theme functions.php. However, it does not work when I add it from child theme functions.php.

remove_action ('after_setup_theme', 'et_pb_setup_theme' , 10);

Remove action has same priority 10 as the add action. Shouldn't it work?

add_action( 'after_setup_theme', 'et_pb_setup_theme' ); //parent theme add_action
up vote 21 down vote accepted

As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so:

add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 );

function wpdev_170663_remove_parent_theme_stuff() {

    remove_action( 'after_setup_theme', 'et_pb_setup_theme' );
}
  • Worked! I have been trying something similar, but my bad! Since I put a condition using has_action to check a still non-existent action in child functions.php, before remove_action it wasn't working!! Thanks a lot! function etn(){ if(has_action('after_setup_theme', 'et_pb_setup_theme')){ remove_action ('after_setup_theme', 'et_pb_setup_theme' ); } } add_action ('after_setup_theme', 'etn', 9); – Smoking Sheriff Dec 9 '14 at 11:18

The functions.php file of child themes is loaded right before the parent theme functions.php, so when you run remove_action in child theme, the action you are trying to remove doesn't exist beacuse it is added later.

  • 1
    ..but doesn't priority 10 and the hook after_setup_theme should take care of that? How should I do this anyway? – Smoking Sheriff Dec 9 '14 at 9:21
  • No, the priority argument is not for that. Simply you can not remove something that doesn't exist. In other words, (taken from codex) you cannot successfully remove the action before it has been added. – cybmeta Dec 9 '14 at 9:38
  • 1
    So, how is it possible to remove an action set by the parent theme? – Aerendir May 27 '17 at 15:21

Try (just change the names):

add_action( 'init' , 'myyy_remove' , 15 );
function myyy_remove() {
        remove_action('ACTION_NAME', 'my_function_name_Something'   ,11);
        remove_action('ACTION_NAME', 'my_function_name_Another'     ,11);
}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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