Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can i change my front end menu depending on if the user is logged in or not?

For Example:

View 1: user is not logged in
menu is : home , about us, testimonials

View 2: user is logged in
menu is : dashboard, my profile, support

Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

Hi @rxn:

Define two menus and serve them based on if they are logged in or not which you can do in your theme's functions.php file:

if (is_user_logged_in()){
  wp_nav_menu( array(
    'menu'            => 'Logged In Menu',
    'container_class' => 'logged-in-menu',
    'theme_location'  => 'logged-in'
  ));
} else {
  wp_nav_menu( array(
    'menu'            => 'Visitor Menu',
    'container_class' => 'visitor-menu',
    'theme_location'  => 'visitor'
  ));
};

You'll also need to register their theme locations which you can do in your theme's functions.php file as well:

register_nav_menus( array(
  'logged-in'  => __( 'Logged-in Menu Area',  'yourtheme' ),
  'visitor' => __( 'Visitor Menu Area', 'yourtheme' ),
));

And you'll have to assign those menus to their menu locations in the admin, like so:

WordPress Admin Menu Locations

share|improve this answer
    
Thank you, Mike. What did you mean by "register their theme locations"? I am using the twentyten theme. What would I put for 'yourtheme'? –  rexposadas Jan 28 '11 at 21:42
    
@rxn - "Register theme locations" means call register_nav_menus() as I showed in code above. As for your theme, create a child theme of TwentyTen instead of using it directly and then put the directory name of your child theme in place of 'yourtheme' "Customizing a WordPress theme without changing it?" wordpress.stackexchange.com/questions/290/… –  MikeSchinkel Jan 29 '11 at 1:55
    
Thank You for putting in the time to answer my question in great detail. –  rexposadas Jan 31 '11 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.