Learn how to fix WP – Beginner’s Guide for WordPress

Learn how to add conditional logic to WordPress menus

Learn how to add conditional logic to WordPress menus

Learn how to add conditional logic to WordPress menus – Do you wish to display various navigation menu items for various WordPress pages? Maybe show logged-in users a separate menu?

You can choose where in your theme to show the navigation menu in WordPress, but by default, it always shows the same menu.

This post will demonstrate how to apply conditional logic to WordPress menus.

Learn how to add conditional logic to WordPress menus

Why Would WordPress Add Conditional Logic to Menus?

Your WordPress website’s navigation menus provide structure and aid in site visitor navigation. All users and all articles and pages on your WordPress website will by default see the same navigation menu.

However, there may be instances when you want to show various menus to various people or on various web pages.

An online shop, a WordPress membership site community or an online learning platform are just a few examples of websites that might profit from customized navigation menus.

For logged-in customers, you might add additional menu items that allow them to manage their accounts, renew their subscriptions, or access the online courses they bought using conditional logic. It is comparable to WordPress menu access control.

With that stated, let’s look at how to use conditional logic in WordPress menus. The subjects covered in this lesson are as follows:

Making New WordPress Navigation Menus

Making the extra navigation menus you want to see in WordPress is the first step. After that, conditional logic may be used to choose when to show each menu.

Just go to the WordPress dashboard’s Appearance » Menus page. This might be your default menu if you already have one that is available to all visitors to your website.

main menu

To build a new menu, you must then click the “add a new menu” link. You might, for instance, establish two menus: one for logged-in users and another for a certain WordPress page or category.

You may see a list of the pages on your website on the left side of the screen. To add a page to your menu, just check the box next to it and click the “Add to Menu” button.

logged in menu

The menu elements on the right side of the screen may also be moved about by dragging and dropping them.

You may choose a position to show your menu farther down the page. However, you are not yet required to provide this menu with a location. In the next phase, we’ll accomplish that.

Don’t forget to click the “Save Menu” button to save your changes.

Changing the Menu for Logged-In Users in WordPress

It’s usually a good idea to show different navigation menus to customers depending on whether or not they’ve signed in to your site.

For logged-in users, you may include a logout link in your menu and offer login and registration options for logged-out users.

You might even add things for your clients that are concealed from the wider public if you operate a WooCommerce business.

Installing and turning on the Conditional Menus plugin is the first step. See our step-by-step tutorial on installing a WordPress plugin for additional information.

After turning it on, choose the “Manage Locations” option from the Appearance » Menus page.

manage menu loctions

You may view the list of places where menus are accessible from here, along with any menus that are presently visible. Depending on the WordPress theme you’re using, these will change.

For instance, on our sample website, it can be seen that the “Main Menu” navigation menu is shown at the Primary Menu position.

By clicking the “Add Conditional Menu” link and choosing a new menu from the drop-down menu, we may instruct the plugin to display a different menu when a certain condition is satisfied. We’ll choose the “Logged in Menu” for this lesson.

select conditional menu

After that, click the “+ Conditions” option.

This will bring up a pop-up window with a list of search options.

logged in user

Simply select the checkbox next to “User logged in” and click the “Save” button.

You may now go to your website to utilize the menu for logged-in users. You may log out of your website to see the menu that is visible to everyone else’s users.

different menu login users

Depending on the user role, different WordPress menus are displayed.

Depending on the user role you assign them, you can also provide them with a customized navigation menu once they log in.

For instance, you may give an administrator access to more menu options while giving contributors access to fewer options. Or, you can give different levels of access to different levels of membership on a membership website.

As in the previous step, you must install and activate the Conditional Menus plugin before you can use the “Manage Locations” option on the Appearance » Menus page.

conditional menus user role menu

The proper conditional menu should be added for the user role you’ve chosen. We’ve chosen the ‘Nav Option Administrator’ menu for this lesson.

The user role may then be selected by clicking the ‘+ Conditions’ link after that.

conditional menus user role check box

To view checkboxes for each user position on your website, select the “User Roles” tab. Simply choose the user roles from which this menu will be visible, and then click “Save.”

Using a Different WordPress Menu for Different Pages

WordPress allows you to show a distinct menu on various pages. On your privacy policy page, for instance, you may include more menu items, such as a link to your cookie notice.

Installing and activating the Conditional Menus plugin is required for this, as seen above. After selecting the proper navigation menu, click the “+ Conditions” option.

You should choose the “Pages” option this time. Every page on your website will be listed for you to view.

conditional menus pages

To show the navigation menu, you must check the box next to each page, then click the “Save” button.

How to Hide the Navigation Menu on Landing Pages in WordPress

You may not want to show a navigation menu at all on certain pages of your website, such as your landing pages.

A landing page is made to boost sales or provide leads for a company. You’ll want to keep people from getting distracted on these pages by giving them everything they need to do a certain task.

The Conditional Menus plugin may be used to do that. This time, while choosing the conditional menu, you must pick “Disable Menu” from the drop-down menu.

conditional menus disable menu

To choose when to show the menu, click the ‘+ Conditions’ link after that.

Your landing pages should have a checkbox next to them once you select the “Pages” tab.

conditional menus landing page

Don’t forget to click the “Save” button in order to save your settings.

Using WordPress Navigation Menus More Effectively

The use of navigation menus in web design is effective. You may use them to direct visitors to the key pages of your website.

You may be wondering how to further modify your navigation menus now that you are displaying them differently on various pages and to different users. 
We really hope that this guide has taught you how to apply conditional logic to WordPress menus. You may also wish to research “How to Manage WordPress Comment Notification Emails“.

Learn how to add conditional logic to WordPress menus

Previous Post
Next Post