Menu Hide Home Page

Hi Guys
I am using StoreFront theme for WooCommerce. I like to display the Primary menu on all pages other than home. I have placed the function below, but not sure if I am on the right track.
I appreciate any help in advance.

# add_action( ‘init’, ‘remove_PrimaryNav’, 50 );
# function remove_PrimaryNav () {
#      if(!is_home()){
#      remove_action( ‘storefront_header’,’storefront_primary_navigation’, 50 );
#      }
# }
Ben NozarDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Hi Ben,

You're sort of on the right-track, but slightly off :)

Firstly, you're hooking into init, which is too early for the is_home and is_front_page functions to work, so you need to change that to a later hook. wp is probably suitable here.

Secondly, the exclamation mark in PHP negates a value, so if (!is_home) is the same as saying 'if it's not home'. You should drop the !

Thirdly, the way is_home() works in WordPress can seem a little quirky, and it depends on how you have your site setup. In the settings, if you have the HomePage set to a Static page, and the Posts page set to another page, the is_home() function will only return true for the Posts page, not the HomePage. To check if you're actually on the homepage, you need to call the is_front_page() function instead.

Wrap all that up in a function and it'll look more like this:

add_action('wp', 'remove_PrimaryNav');
function remove_PrimaryNav () {
    if( is_front_page() ) {
        remove_action('storefront_header','storefront_primary_navigation', 50 );
    }
} 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben NozarDirectorAuthor Commented:
Perfect, Work like a charm. Thank you very much, appreciated.
0
Chris StanyonWebDevCommented:
No worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
woo commerce

From novice to tech pro — start learning today.