Do you want to show different navigation menu items for different pages in WordPress? Or display a different menu for logged in users?
WordPress allows you to display a navigation menu in a specific location in your theme, but by default it will always display the same menu.
In this article, we will show you how to add conditional logic to menus in WordPress.
Why Add Conditional Logic to Menus in WordPress?
Navigation menus give your WordPress website structure and help visitors find what they are looking for. By default, your WordPress site will display the same navigation menu for all users and on all posts and pages.
However, there may be times when you want to display different menus for different users or on different pages of your website.
Websites like an online store, a community of WordPress membership sites, or an e-learning platform can all benefit from custom navigation menus.
Using conditional logic, you can add additional menu items for logged-in users so they can manage their accounts, renew subscriptions, or view online courses they’ve purchased. You can think of it as a WordPress menu access control.
That said, let’s see how to add conditional logic to menus in WordPress. Here are the topics we will cover in this tutorial:
The first step is to create the additional navigation menus you want to display in WordPress. After that, you can use conditional logic to decide when each menu will be displayed.
Just head to the Appearance » Menus page in the WordPress dashboard. If you already have a navigation menu that you use on your website for all users, this might be your default menu.
Then you need to click on the “Create a new menu” link to create a new menu. For example, you can create a menu to display for logged in users and another to display on a certain WordPress page or category.
On the left side of the screen, you can see a list of your website pages. Simply check the box next to the page you want to add to your menu and click the “Add to Menu” button.
You can also drag and drop menu items on the right side of the screen to rearrange them.
Further down the page, you can choose a location to display your menu. But, you don’t need to assign a location to this menu now. We will do that in the next step.
Don’t forget to click the “Save Menu” button to save your changes.
For more details on creating menus, you can check out our beginner’s guide on how to add a navigation menu in WordPress.
It’s often useful to show different navigation menus to users depending on whether or not they’ve logged in to your site.
For example, you can include login and register links for logged out users and add a logout link to your menu for your logged in menu.
Or if you run a WooCommerce store, you can include items for your customers that are hidden from the general public.
First, you need to install and activate the Conditional menus connect. For more details, see our step-by-step guide on how to install a WordPress plugin.
Upon activation, you must visit the Appearance » Menus page and switch to the “Manage Locations” tab.
From here you will see the list of available menu locations and the menus that are currently displayed. These vary depending on the WordPress theme you are using.
For example, on our demo website, it says that our main menu location displays a navigation menu titled “Main Menu”.
We can tell the plugin to display a different menu when a certain condition is met by clicking on the “+ Conditional Menu” link and selecting another menu from the drop-down menu. For this tutorial, we will select “Connected Menu”.
Next, you need to click on the ‘+ Conditions’ link.
This will bring up a pop-up where you’ll see a bunch of conditions to choose from.
Simply check the box next to the “Logged in user” option, then click the “Save” button.
You can now visit your website to see the logged in user menu in action. You can log out of your website to see the navigation menu that appears to all other users.
For more detailed instructions and how to do this using code, see our guide on how to show different menus to logged in users in WordPress.
After a user has logged in, you can also display a different navigation menu depending on the user role you assigned to them.
For example, you can include additional menu items for an administrator and more limited items for a contributor. Or on a membership site, you can grant different levels of access to different levels of membership.
As in the previous section, you must install and activate the Conditional menus plugin, then visit the Appearance » Menus page and switch to the “Manage Locations” tab.
You must add the appropriate conditional menu for the user role you will select. For this tutorial, we have selected the ‘Nav Menu Administrator’ menu.
After that, you need to click on the “+ Conditions” link to be able to choose the user role.
You will need to click on the “User Roles” tab to see the checkboxes for each user role on your website. Simply click on the user roles that will see this menu, then click the “Save” button.
To do this, you need to install and activate the Conditional menus plugin, as shown above, then choose the appropriate navigation menu and click the “+ Terms” link.
This time you need to click on the “Pages” tab. You will see a list of every page on your website.
You need to place a check mark next to each page where you want to display the navigation menu and then click on the ‘Save’ button.
Hide navigation menu on landing pages in WordPress
There may be pages on your website where you don’t want to display a navigation menu at all, such as your landing pages.
A landing page is designed to increase sales or generate leads for a business. On these pages, you’ll want to minimize distractions and provide users with all the information they need to perform a specific action.
In our guide on how to increase your landing page conversions by 300%, we suggest minimizing distractions by removing navigation menus and other links from the page.
You can do this using the Conditional menus connect. When you select the conditional menu, this time you need to choose “Disable menu” from the drop-down menu.
Then you need to click on the ‘+ Conditions’ link to choose when to show the menu.
You need to click on the “Pages” tab and place checkmarks next to your landing pages.
Don’t forget to click the “Save” button to save your settings.
Navigation menus are a powerful web design tool. They allow you to direct users to the most important sections of your website.
Now that you’re showing different navigation menus on different pages and for different users, you might be wondering how you can customize them further.
Try these helpful tutorials to extend the functionality of navigation menus on your WordPress site.
We hope this tutorial helped you learn how to add conditional logic to menus in WordPress. You might also want to learn how to create automated workflows or check out our list of the best social proof plugins for WordPress and WooCommerce.