Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally remove Storefront handheld menu for a single page

I am attempting a relatively simple modification of code provided by Woocommerce to remove the handheld navigation bar on a single page of my site with the slug register.

The code snippet provided is:

add_action( 'init', 'jk_remove_storefront_handheld_footer_bar' );

function jk_remove_storefront_handheld_footer_bar() {
  remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
}

I want to remove the menu only for a single page, so I tried to use the is_page hook.

add_action( 'init', 'remove_storefront_handheld_footer_bar' );
function remove_storefront_handheld_footer_bar() {
    if (is_page( $page = 'register' )){
            remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
        }
}

However, this does not remove the handheld menu. If I remove my is_page logic, then the menu disappears but that is not the functionality I need.

like image 337
roody Avatar asked Dec 02 '25 13:12

roody


1 Answers

You can use instead storefront_footer (the same hook) with a higher priority (lower number) than the priority used in remove_action() like:

add_action( 'storefront_footer', 'remove_storefront_handheld_footer_bar' );
function remove_storefront_handheld_footer_bar() {
    if ( is_page( 'register' ) ){
        remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works (with any specific page ID, name or slug). You need to be sure that "register" is the slug of a real existing "page".

like image 129
LoicTheAztec Avatar answered Dec 04 '25 07:12

LoicTheAztec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!