How to Use the Function is_user_logged_in To Display Different Menus?

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' ) );
}

Leave a Comment