If you’re using WordPress as a membership site, you may want to display a special navigation menu to logged in members.
There’s different ways to do this using either CSS classes or PHP code.
Custom functions are the best way to go in my opinion because you don’t have to worry about adding more CSS to your child themes files and slowing down your site. PHP code is more powerful and efficient. You also don’t need to worry about cross browser issues.
To display a different nav menu for logged in and logged out users, you firstly need to create 2 menu’s.
I won’t show you how to do that because its so easy even your mum could do it!
Create 2 nav menus
- One for Logged in members
- And one for logged out visitors
Here’s what they look like once you’ve created them.
You can then select the non-members menu as the primary menu and leave the members menu unassigned.
You’d probably want to include a registration link in the non members nav menu but not in the members menu.
Paste Code In Functions File
This is the code you need to paste into your child themes functions.php file.
Here’s some code which you can use to display the nav menu for logged in members in a different location like the footer for either the primary or secondary nav menu’s.
Nav Menu Roles Plugin
Here’s a plugin which pretty much does the same thing as the code snippets above.
This plugin enables you to hide menu items based on user roles. You can:
- Limit display of this menu item to users who are logged in or out, or customize by role.
- Limit display of this menu item to users of selected roles.
Nav Menu Items Visibility Plugin
The conditional tag to hide menu items for logged in users is:
That’s all folks!
I know there are other ways to display different menus for logged in and logged out users however these are the best in my opinion.
How about you? Do you have a better solution than this one?