In my Facebook group a user asked:
I love all your posts. I'm looking for help for something simple. I have a membership site, and I need to swap out my secondary menu based on whether the visitor is logged in or not.
Here are the requirements:
- For non-logged in visitors, show
Login Menu
menu in Secondary Navigation theme location. Add Login link automatically at the right. - For logged in users, show
Member Links
menu in Secondary Navigation theme location. Add Logout link automatically at the right.
For non-logged in visitors:
For logged in users:
Step 1
At Appearance > Menus go to Manage Locations tab and assign a menu to Secondary Navigation Menu. It does not matter what menu this is. This is going to be replaced with one of the two custom menus you are going to create next.
Create two custom menus named Login Menu
and Member Links
and add your desired links. Note that the Login and Logout menu items are set to be automatically added.
Step 2
Add the following in child theme's functions.php:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
A+
PERFECT! Just what I needed. Thank you so much. My membership here is one of the best investments I made last year.
How might I set this menu to show if I am using the Menu in the Header Right Widget?
I have the same question as Mike, because I followed another tutorial here, to put the menu in the Header Right Widget. I’d love to be able to do this for my client’s members.
The easiest method would be to remove the Header Right widget area and relocate the Secondary Navigation Menu to Header Right location.
Add this in functions.php: http://pastebin.com/raw/JpsfJ1T3
Hi Sridhar, I used the code in http://pastebin.com/raw/JpsfJ1T3 but the result is not exactly what I was looking for. I removed the pastebin code from functions.php and for some reason the secondary nav will not go back to where it was originally. Do you know why this happens? And most importantly, can you please let me know how to undo the pastebin code? I’m using Cafe Pro theme. Thank you so much.
Hi Sridhar, please disregard my previous message – I replaced the functions.php file with a backup functions.php file and the nav is now back in its original spot, so I’m good to go! Thank you for sharing your code, it’s very helpful!