How to Show Custom Menus to Logged In WordPress Users

How to Show Custom Menus to Logged In WordPress Users


If you’re building a website using WordPress which requires users to login to the site, then you will most likely need to have a dynamic navigation menu, which displays different menu items to users if they are logged out, logged in or have a specific user role.

This is because it makes no sense to show a register or login link to users who have already logged in or provide a link to a user’s profile when they are a visitor and do not have a profile on your website.

How To Add Custom Menus For Logged In Users

Whilst different plugins exist for creating dynamic navigation menu, we are going to explain how to create dynamic menus using the free User Menus plugin by Jungle Plugins.

User Menus Plugin Features

The plugin provides three main sets of features which are useful for creating dynamic menus:

  1. Visibility controls for menu items e.g who can see each menu item (everyone, logged out users, logged in users, specific user roles)
  2. Logged in user information in the navigation menu e.g “Hello, John Doe”
  3. Login and logout links for navigation menu

Using The User Menus WordPress Plugin

User Menus Free WordPress Plugin

As User Menus is a free plugin hosted on the WordPress.org plugin directory you can install the plugin by doing the following:

  1. Log into your WordPress installation
  2. From the Dashboard, navigate to Plugins > Add New
  3. Search for User Menus (created by Jungle Plugins & Daniel Iser)
  4. Click the Install Now button
  5. Once the plugin is downloaded and installed, click to Activate Plugin

Applying visibility controls to menu items

To apply visibility controls to menu items you need to do the following:

  1. From the Dashboard, navigate to Appearance > Menus
  2. Add a new menu item to your menu or expand an existing menu item
  3. Open the Who can see this link dropdown and select either Everyone, Logged Out Users or Logged In Users (Everyone is default option)
  4. If you select Logged In Users you will then be able to select which user roles can see the menu item if you wish to restrict a menu item to a certain user role(s) only
  5. Once you have applied your desired visibility controls to your menu, click the Save Menu button

screenshot-1

Display logged in user information in the navigation menu

Many popular websites where users login to use the site, will show a user’s name in the website header to show a user that they are logged into their website (take WPExplorer for example – you should either see “login” or your username on the right side of the navigation menu).

To do this on your website using  the User Menus plugin you need to do the following:

  1. From the Dashboard, navigate to Appearance > Menus
  2. Add a new menu item to your menu or expand an existing menu item
  3. Open the “Who can see this link” dropdown and select Logged In Users
  4. Go to the menu item’s navigation label field and click on the grey button with the arrow
  5. Select the user information you want to show in the menu item e.g {first_name}, {last_name}, {username}, {display_name}, {nickname}, {email}
  6. Click the Save Menu button

Now when a user logs into your website they will see their name in your website’s navigation menu.

screenshot-2

Add a login and logout link to your menu

The final thing you’ll want to add to your navigation menu are links for users to login and logout of your website.

To add this to your website simply use the following steps:

  1. From the Dashboard, navigate to Appearance > Menus
  2. In the add a new menu item accordion, click on User Links to expand the menu item type
  3. Select the checkbox for the Login and Logout links and click the Add to Menu button
  4. Expand the menu items and open the “Where should users be taken afterwards?” dropdown and select either Current Page (default option), Home Page or Custom URL (if selected you will then need to enter a url user should be redirected to)
  5. Click the Save Menu button

screenshot-3

That’s it!

You’ve now added a dynamic navigation system to your website to improve the experience for your website’s users. Have any questions? Or want to share your own experience using User Menus or another plugin? Just leave a comment below – we’d love hear from you.



Source link

Share this post

Do NOT follow this link or you will be banned from the site!