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.

So, I want to create different menus for people who are logged in or not.

I got a reply that i should use a function

if (is_user_logged_in()) {
      wp_name_menu(array('theme_location' => 'logged_user' ));
} else {
      wp_nav_menu(array('theme_location' => 'new_user' ));
}

So, if I get this right, I put this into functions.php which is located in my child theme (anywhere inside the file?), then I create another menu and where it is "logged_user" and "new_user" I enter the names of the menus?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

i just did this for a site i am working on. first i registered 2 menus in functions.php:

add_action('init','kia_menus');

function kia_menus(){

    register_nav_menus( array('primary-menu' => __( 'Primary Menu for Logged In Users', 'kia_theme' ), 
            'primary-loggedout' => __( 'Primary Menu for Logged Out Visitors', 'kia_theme')
                                    ));
}

and then where i want the 1 menu to appear based on the user's status (probably in header.php but depends on your theme):

if( !is_user_logged_in() ){
    wp_nav_menu( array( 'theme_location' => 'primary-loggedout' ) );
} else {
    wp_nav_menu( array( 'theme_location' => 'primary-menu' ) );
}
share|improve this answer
    
so the first part goes to functions.php and the second one to the place where i want the menus to be? In the second part do I have to change theme_location to the location or just leave it like that? And in the first part where it is kia_theme I would have to enter my child themes name which would look like Corporate_theme? I'm sorry for these newbie questions but I have no experience in coding –  Gediminas Mar 4 '12 at 16:39
    
yes part 1 goes in functions.php and yes the 2nd part goes where you want to display the menu. the theme_location can be whatever, but it needs to match what you declared in register_nav_menus. kia_theme is my text domain for translation purposes. you can make it be anything and if you don't plan to make your theme translatable, you don't need it at all. –  helgatheviking Mar 4 '12 at 18:00
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.