0

My question is how do I remove the action hook in the parent from the child theme? Code from my parent theme:

if ( ! function_exists( 'wm_menu_social' ) ) {
    function wm_menu_social() {
        get_template_part( 'template-parts/menu', 'social' );
        // if i place a comment here, social links won't display    
    }
} 
    add_action( 'tha_header_top', 'wm_menu_social', 130 );

I tried adding each of these 3 possible add_action() individually from my child theme but didn't work:

add_action( 'after_setup_theme', 'wm_remove_menu_social', 0);
//add_action( 'init', 'wm_remove_menu_social');
//add_action( 'wp_head', 'wm_remove_menu_social');

function wm_remove_menu_social() { 
   remove_action( 'tha_header_top', 'wm_menu_social' );
   echo "TESTER"; // this prints but remove action doesnt work.
}

As shown above, I tried to add a comment to the parent & it worked. But, we all know that the parent theme should not be touched for future updates. I've searched this problem but nothing seemed to work. Sorry guys, I'm still a bit new to the Wordpress API. I have created very few basic WP plugins. Thanks in advance.

1

The priority argument of add_action and remove_action need to be the same. Since wm_menu_social is hooked at 130 you need to specify 130 when removing it:

remove_action( 'tha_header_top', 'wm_menu_social', 130 );

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.