I'm creating a website which will provide services to members and I want to make it so that when a not logged in person comes to the website the menu is specifically designed for sales pages to make him register, but when a logged in person comes in he sees a different menu that is for the sole purpose of delivering the services. I want to make this because I don't want my already members always going to the website to read the sales pages. I would so appreciate your help, just can't figure this out on my own. And I think this would be pretty neat also :) hoping for an answer
-
"use is_user_logged_in conditional tag and apply a different menu accordingly" Cool, but where do I put this?– GediminasCommented Mar 4, 2012 at 15:05
-
Search your themes templates until you find your menu. Then alter this with the code mentioned in the answer below.– kaiserCommented Mar 5, 2012 at 1:02
Add a comment
|
1 Answer
You can do that by using 2 different menus (wp_nav_menu).
use is_user_logged_in conditional tag and apply a different menu accordingly:
if (is_user_logged_in()) {
wp_nav_menu(array('theme_location' => 'logged_user' ));
} else {
wp_nav_menu(array('theme_location' => 'new_user' ));
}
Edit This code goes where you'd usually put your regular menu in the theme - probably header.php
Also, make sure that you add the menus to the actual theme, i.e. in function.php add the folowing lines of code:
if (function_exists('register_nav_menu')):
register_nav_menu('logged_user', 'Existing users menu');
register_nav_menu('new_user', 'New users menu');
endif;
-
-
-
@hannit_cohen where would I put this code in? I have a child theme, if that helps. Commented Mar 4, 2012 at 15:14
-
-
1"But where do I put this code in?" only you can answer that question, as it is entirely dependent upon your Theme. See the
wp_nav_menu()
Codex entry that @hannitcohen linked in his answer. Commented Mar 5, 2012 at 14:21