wordpresswoocommercethemesstorefrontwordpress-hook

remove_action is not working for me to remove a theme's action..?


I'm running WordPress + WooCommerce + Storefront. I'm trying to remove the "Built with Storefront & WooCommerce" credit in the footer.

I see lots of articles explaining how to do that by using remove_action as follows:

remove_action('storefront_footer', 'storefront_credit',20);

This is not working, though. I've tried it through a Snippets plugin, and I've tried it through the functions.php in my child theme.

I've also verified that nothing seems to have changed in the theme code since these articles were written, so it has the same function and hook names.

I'm not sure what I'm missing here..?? Any information on this would be greatly appreciated. Thanks!


Solution

  • In order to remove the action you must be sure to remove it before it's added. This is a parent theme's hook, so if you remove_action from the child theme or via code Snippets, it's already too late.

    Unless... you make the remove_action trigger earlier, by hooking that to "wp" WordPress action.

    Try with:

    add_action( 'wp', 'bbloomer_remove_storefront_actions' );
    
    function bbloomer_remove_storefront_actions() {
       remove_action( 'storefront_footer', 'storefront_credit', 20 );
    }
    

    Another cool thing you can do to absolutely make sure you can remove an action is by using the same hook, but with a lower priority:

    add_action( 'storefront_footer', 'bbloomer_remove_storefront_actions', 19 );
        
    function bbloomer_remove_storefront_actions() {
       remove_action( 'storefront_footer', 'storefront_credit', 20 );
    }
    

    In this example, I'm removing 'storefront_credit' which has priority = 20 by hooking into the same hook, with priority 19, so that I remove it before it's added.