Navigation or menu is one of the important elements in every website. It usually provide useful links to various important pages on your site – About page, Contact page, sitemap etc. On most websites, you can find it on the top part of the site, usually either before or after the site header.
In WordPress, you can differentiate users based on their user roles. Default user roles are Super Admin (for Multisite only), Administrator, Editor, Author, Contributor, and Subscriber. These are default roles and of course, you can create your own. WordPress Codex has great explanations about the user roles and capabilities.
Since there are many different level of users, therefore it’s possible to show certain menu on certain user only. Therefore, in order to conditional menu based on user roles, instead of writing a very long code, we can use a plugin called Nav Menu Roles. This plugin is available for free from the official WordPress plugin repository.
1. Install and activate the Nav Menu Roles plugin.
2. If you haven’t created your menu, you need to create one. It’s really easy and I’ve written a tutorial on setting up WordPress menu long time ago.
3. Once you’ve activated the plugin, it will add a new meta box under each menu. The UI is very intuitive and you just need to decide on which users the item will be showing up.
- The default Display Mode is By Role with all Access Roles are unchecked. This means that the item will be shown on every users.
- There are options to show the item on all logged out or all logged in users only.
- However, if you choose to show the item for all logged out or logged in users only, the Access Role option below it does not work.
This plugin works out of the box. Just install and activate, no other further configurations needed. Then, you may set out to show the menu based on user roles per item.
Leave a Reply