How to Show Different Menus to Logged in WordPress Users

3
178
Show Different menus to Logged in WordPress Users

In WordPress, there is an option to create multiple menus but no condition to make it visible only for logged in users or guest. Users might need this option to show different menus to logged in WordPress users for various scenarios like “login menu and guest post items should visible only for guest” and “logout button should visible only for logged in users”.

See Also: 10+ Most Common WordPress Mistakes to Avoid

Create Two Menus – (if not created it already)

  1. Login to WordPress admin dashboard.
  2. Navigate to Appearance Then Menus.
  3. Click create new menu.
  4. Create two menus. I have created two menus with name guest and logged-in.

Show Different menus to Logged in WordPress Users

See Also: Top 16 Best Free Essential WordPress Plugins

Using code – Show Different Menus to Logged In WordPress Users

Add the below lines to the functions.php file in the theme folder.

Modify logged-in and guest with your menu name. Save the file. Now you can see logged-in menu will appear only to logged in users and guest menu will appear only to guests.

See Also: How to make WordPress site Load Faster

If your theme has eligible to display more than one menu

The above method will work only if your theme has one menu location. If it has more than one menu to display like header menu, main menu, footer menu, social menu etc, then the above method will display the same logged-in and guest menus in all the menu location overriding the settings in Menus panel. So apply the below method if your theme contains more than one menu location.

Add the below lines to the functions.php file in the theme folder.

Modify the header-menu to your menu location name. You can find your menu location name in the theme’s header file or from your theme provider. Modify logged-in and guest with your menu name. Save the file. Now you can see the logged-in menu and guest menu will appear only in the header menu and remaining menu locations will be unaffected.

See Also: Prevent WordPress Content Theft – text and images

Using Plugin – Show Different Menus to Logged In WordPress Users

Above methods are applicable only to advanced users. Basic users can easily accomplish the same using any of the below plugin instead of editing the functions.php file.

  1. Nav Menu Roles
  2. If Menu
  3. Menu Item Visibility Control

See Also: Top 3 Best Free WordPress Security Plugins

3 COMMENTS

LEAVE A REPLY