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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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' );
}
Method 2
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.
Method 3
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);
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0