Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Add Conditional Logic to Menus in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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 show a navigation menu in a specific location in your theme, but by default, it will always show the same menu.

In this article, we will show you how to add conditional logic to menus in WordPress.

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’re looking for. By default, your WordPress website will display the same navigation menu to all users and on all posts and pages.

However, there may be times when you wish to display different menus to different users, or on different pages on your website.

Websites like an online store, a WordPress membership site community, or an online learning platform can all benefit from personalized navigation menus.

Using conditional logic, you could add extra menu items for logged in users so they can manage their accounts, renew their subscriptions, or view the online courses they purchased. You can think of it as WordPress menu access control.

With that being said, let’s take a look at how to add conditional logic to menus in WordPress. Here are the topics we’ll cover in this tutorial:

Creating New Navigation Menus in WordPress

The first step is to create the additional navigation menus you wish to display in WordPress. After that, you can use conditional logic to decide when each menu will be displayed.

Simply head over 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, then this can be your default menu.

Main menu

Next, you need to click the ‘create a new menu’ link to create a new menu. For example, you could create one menu to show to logged in users, and another to display on a certain WordPress page or category.

On the left-hand side of the screen, you can see a list of your website pages. Simply check the box next to any page you want to add to your menu and click the ‘Add to Menu’ button.

Logged in menu

You can also drag and drop the 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’ll do that in the next step.

Don’t forget to click on the ‘Save Menu’ button to store your changes.

For more details on creating menus, you can take a look at our beginner’s guide on how to add a navigation menu in WordPress.

Showing a Different Menu to Logged In Users in WordPress

It’s often useful to display different navigation menus to users depending on whether they have logged in to your site or not.

For example, you can include login and registration links for logged out users and add a logout link to your menu for your logged in menu.

Or if you are running a WooCommerce store, then you could include items for your customers that are hidden from the general public.

First, you need to install and activate the Conditional Menus plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Appearance » Menus page and switch to the ‘Manage Locations’ tab.

Manage menu locations

From here, you will see the list of available menu locations and the menus that are currently displayed. These will vary depending on the WordPress theme you are using.

For example, on our demo website, it is showing that our Primary Menu location is showing a navigation menu titled ‘Main Menu’.

We can tell the plugin to show a different menu when a certain condition is matched by clicking on the ‘+ Conditional Menu’ link and selecting another menu from the drop down menu. For this tutorial, we’ll select ‘Logged in Menu’.

Select logged in menu

Next, you need to click on the ‘+ Conditions’ link.

This will bring up a popup where you’ll see a bunch of conditions to choose from.

Select logged in user aa the condition

Simply check the box next to the ‘User logged in’ option, and then click on 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 is shown to all other users.

Different menu for logged in users

For more detailed instructions and to learn how to do this using code, take a look at our guide on how to show different menus to logged in users in WordPress.

Showing a Different WordPress Menu Depending on User Role

Once a user has logged in, you can also display a different navigation menu depending on the user role you have assigned to them.

For example, you could include extra menu items for an administrator and more limited items for a contributor. Or on a membership site, you could grant different levels of access to different membership levels.

As in the previous section, you need to install and activate the Conditional Menus plugin, then visit the Appearance » Menus page and switch to the ‘Manage Locations’ tab.

Select the Conditional Menu

You should add the appropriate conditional menu for the user role you will select. For this tutorial, we’ve selected the ‘Nav Menu Administrator’ menu.

After that, you need to click the ‘+ Conditions’ link so you can choose the user role.

Select the Roles That Should See the Menu

You will need to click on the ‘User Roles’ tab to see checkboxes for each user role on your website. Simply click the user roles that will see this menu, and then click the ‘Save’ button.

Showing a Different Menu for Different Pages in WordPress

You can display a different menu for different pages in WordPress. For example, you could display extra menu items on your privacy policy page, such as a link to your cookie notice.

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 ‘+ Conditions’ link.

This time you should click the ‘Pages’ tab. You will see a list of every page on your website.

Select the Pages Where the Menu Should Be Displayed

You need to place a checkmark next to each page where you wish to display the navigation menu, then click the ‘Save’ button.

Hiding the 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 will want to minimize distractions and provide users with all the information they need to take a specific action.

In our guide on how to increase your landing page conversions by 300%, we suggest that you can minimize distractions by removing navigation menus and other links from the page.

You can do that using the Conditional Menus plugin. When selecting the conditional menu, this time you need to choose ‘Disable Menu’ from the drop down menu.

Select Disable Menu From the Drop Down

Next, you need to click the ‘+ Conditions’ link to choose when to display the menu.

You should click on the ‘Pages’ tab and place checkmarks next to your landing pages.

Select the Pages Where the Navigation Menu Should Be Hidden

Don’t forget to click the ‘Save’ button to store your settings.

Doing More With WordPress Navigation Menus

Navigation menus are a powerful web design tool. They allow you to point users to the most important sections of your website.

Now that you are showing different navigation menus on different pages and for different users, you may be wondering how you can customize them further.

Try these useful tutorials to extend the functionality of the navigation menus on your WordPress website.

We hope this tutorial helped you learn how to add conditional logic to menus in WordPress. You may also want to learn how to create automated workflows, or check out our list of the best social proof plugins for WordPress and WooCommerce.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

36 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Bet Hannon says

    Be VERY careful with making menus different across your site. It’s not a problem to show different menus to logged in/out users, but to meet WCAG 2.0+ accessibility standards, main menus should be consistent page to page.

    • WPBeginner Support says

      Thank you for sharing that for those attempting to have those standards for their site. :)


  3. Kevin says

    I don’t see the “Enable conditional logic” under Appearance -> Menu. I’m using WordPress 5.7 as of March 16, 2021.

    • WPBeginner Support says

      The wording may have changed since this article but there should still be a checkbox for changing the visibility.


  4. Richard S. says

    BIG Thank you for this article, it’s awesome.
    Your snippet of code was perfect for a project I was working on, as was this plugin which I’m now using.
    Even in 2019 this is a handy page, it’s working well on WordPress 5.2.3 (Astra Pro theme) so still very applicable.

  5. Vasim Shaikh says

    I would like to ask I have added role for user Author and subscriber both then its should be display to author not subscriber. how to handle this?

  6. Rudolf says

    Really simple and easy to use plugin. Fantastic! It did not only save me a lot of time but also an organizational advantage because instead of using widget logic with different menu widgets, I create now one 1 menu with conditions per item.

  7. Jonathan P says

    Thank you,

    I have only used this plugin for conditions for users that are logged in or not logged in, but it works great, it really has saved me hours of messing around with code.

  8. Kiva says

    Could I set up this plugin so that I can set up different menu options for each different category?

  9. David says

    Thank you guys for sharing this. However it will display a PHP Notice on conditioned menu items and the custom condition won’t be displayed among condition options, if you don’t specify the id parameter.

  10. Paul says

    Hi, I added conditions (if a string matches the server name, a menu is hidden). Great! But I would like to add even more custom conditions. Could you show an example of the code you would use to add more than on name/condition pair the custom option?

    name = “If the site is not www.”
    condition = www is not in SERVER_NAME
    name = “Paul site.”
    condition = “paul is in SERVER_NAME”



  11. Isuru says

    This Conflicts the WP User Manager Pro, and then user manager Pro plugin functions not working due to the confliction.
    as an ex: Show password tick in user registration page doesn’t work, as well as login page also not functioning well.
    can you please fix this

  12. Mo says

    Yep, definitely broken.

    Works great for the built in conditions, but when coding custom conditions it works once and then stops working.

  13. jban says

    YES!!! After 90 minutes of trying to figure this out, this article made it work for me. THANK YOU!!!

  14. Mohi says

    I installed this plugin, but I am getting an warning as follows :

    Warning: Missing argument 2 for custom_nav_edit_walker() in /var/www/equest/wp-content/themes/wp-questrian/framework/megamenu/mega-menu.php on line 42

    How to solve this warning ? Please guide me.

  15. JMD says

    I have not used the If Menu plugn, but I tried the Nav Menu Roles plugin

    It works but then conflicts with the Mega menu functionality of my theme.

    I am hesitant to try the If Menu plugin mainly because it has not been updated in so long. It will be a matter of time before I have to remove it for sure.

  16. Peter says

    Could not get this plugin to work. Not showing up i menu-items. Using: WP 4.3 / Nimwa theme.

    Any suggestions on similar working plugin? Just want to hide some menu items while working on them…

  17. Chuks Eke says

    Could this be achieved with this plugin,
    I want to have different menu for different pages or post. for example,

    Home | About Us | Service | Contact

    About Us [ History | Team | Career ]
    Services [ Web Development | Window Application | Corporate ID ]

    Is it possible with this plugin to show sub menu on side menu for About Us

      • Dieter says

        I stopped installation after reading WP Org PlugIn Page, there is the comment “1 person says it is broken” and in the support section is an open report which is not solved.
        If I read something like this I don’t even try to install such plug in.

      • Jagabandhu says

        The plugin is not working. It’s not showing “enable conditional logic” and the plugin author is not responding from last 7 months.

        Tried with disabling other plugins. But no result.

        Is there any other plugin to do so!?
        I need it.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.