How to Add Conditional Logic to WordPress Menus

If visitors can’t find their way around your website, they won’t stick around for long.

That’s why your WordPress menus are so important — they’re the easiest way for visitors to navigate your website.

Sometimes, though, a one-size-fits-all approach to menu building simply doesn’t work.

What if there’s a WordPress menu item that you only want showing up for Admin users? What about a page that’s only relevant to users that are logged in to your website? How about a menu button that sends premium members to exclusive content?

This requires conditional logic functionality, which you can use to show or hide navigational menu items based on post type, category, user type, and more.

Today I want to show you how to add conditional logic to WordPress menus, using the If Menu plugin. The plugin is available completely free of charge from the WordPress repository.

How to Use If Menu

Let’s kick things off by installing the If Menu plugin. Login to WordPress, then navigate to Plugins > Add New > search for ‘If Menu’ > Install Now > Activate Plugin.

Conveniently, there are no settings to configure, so you can start using the plugin straight away by clicking Appearance > Menus. This is where you edit your navigational menus and specify what conditional logic you want to show up on your site.

Choose one of the menu items, then check the Enable Conditional Logic box. Now you’ll be able to configure your conditional logic.

This is actually really easy to do, thanks to some intuitive drop-down menus.

If Menu conditional logic

The plugin allows you to specify the conditions for a menu item to be displayed/hidden. The options include:

  • User is logged in
  • User is Admin
  • User is Editor
  • User is Subscriber
  • User is Author
  • User is Contributor
  • Front Page
  • Single Post
  • Page

So, for example, you might only want to show a menu item on your homepage. In such a scenario, you would simple select the Show and Front Page options.

Or perhaps you have a guidelines page for your team of writers — there’s no need for a regular visitor to see this page, is there? In this instance, you would simply select Show and User is Contributor from the list of options.

When you’re done configuring your conditional logic, remember to hit the Save Menu button, otherwise you’ll lose all your unsaved changes.

Before assuming the job is done, it’s well worth manually checking your website to ensure the conditional logic is working for all user levels.

Final Thoughts

Conditional logic allows you to build fully functional custom menus for different user roles, or for specific pages/posts. This enables you to improve navigation beyond what the default menu-building functionality is capable of.

If you want to add conditional logic to your WordPress menus, If Menu is one of the best plugins for the job. This is because of the streamlined approach it takes — nothing is overcomplicated. Simply plug and play, with the intuitive drop-down menus ensuring things don’t get too confusing. A highly recommended plugin!

Do you use conditional menus on your WordPress website? Share your thoughts and experiences in the comments below!

 

New Posts in your inbox