This code enables you to display a different menu on your front page.
The code is written to change the primary menu on the front page however you can change the is_front_page() conditional tag to any other.
It works in any theme and should be placed at the end of your child theme functions.php file.
You will need to create 2 menus:
- One menu named primary
- And one named front
1. primary menu
Here’s the settings you need to use for the menu named primary:
Under the Menu Settings > Theme locations, check the box to assign the menu to the Primary Navigation Menu location.
2. front menu
Here’s the settings you need to use for the menu named front:
Under the Menu Settings > Theme locations, uncheck the box to assign the menu to the Primary Navigation Menu location.
Conclusion
So to wrap up, the Menu Settings > Theme Locations settings should be checked for the primary menu which displays on all pages excluding the front page.
And the Menu Settings > Theme Locations settings for the front menu should be unchecked as the code controls the setting for this menu so it only displays on the front page.
This is one solution which enables you to remove the default primary nav menu from your front page and show a custom menu instead without removing the primary menu from the rest of your site.
Was This Tutorial Helpful?