Web Design

WordPress Buddypress Different Menu for Logged In and Non-Logged in Users

By | Web Design | 2 Comments

I’ve been in the process of building an online community for the Utah Grotto of the National Speleological Society and ran into a wall when it comes to creating a different menu for logged in and non logged in users. The primary problem was in the fact that several of the buddypress supported themes only support one menu and you need at least two in order for the is_user_logged_in() function to work properly. So here was the solution I came up with after referencing the following sites: and

  1. In the functions.php file of the theme in which you are using add  the following code in order to support two different menus that you define in Appearance > Menus within WordPress
    // This theme uses wp_nav_menu() in one location.
    	register_nav_menus( array(
    		'primary' => __( 'Primary Navigation', 'buddypress' ),
    	) );
    // I added this line to support a second menu for logged out users
    	register_nav_menus( array(
    		'secondary' => __( 'Secondary Navigation', 'buddypress' ),
    	) );
  2. Now log into WordPress and go to Appearance > Menus and create two different menus, one for logged in users and one for logged out users. For more information on using Menus go to
    Wordpress Menus Screenshot

    After logging into your wordpress site go to the “Appearance” menu item on the left and then to “Menus”

  3. Finally add the following code to your header.php file in your theme folder, wherever the menu code appears. I swapped this line of code:
    <?php wp_nav_menu( array( 'container' => false, 'menu_id' => 'nav', 'theme_location' => 'primary', 'fallback_cb' => 'bp_dtheme_main_nav' ) ); ?>

    for this code:

    if ( is_user_logged_in() ) {
        wp_nav_menu( array( 'container' => false, 'menu_id' => 'nav', 'theme_location' => 'primary', 'fallback_cb' => 'bp_dtheme_main_nav' ) );
    else {
        wp_nav_menu( array( 'container' => false, 'menu_id' => 'nav', 'theme_location' => 'secondary', 'fallback_cb' => 'bp_dtheme_main_nav' ) );
  4. That’s it.