WordPress menu has been assigned but not showing

So I’m quite new to the whole WordPress thing but I’m experienced with HTML/CSS anyway. I’ve created a new Menu within the Admin area of WordPress but when assigned to the theme, it still doesn’t show correctly. Apologies in advance if I’m being totally blind here but PHP isn’t my strong point too.

So below is the code in question, related to where the menu is in the header section:

Read More
<div id="nav-primary" class="nav"><nav>
    <?php if ( is_user_logged_in() ) {
        wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) ); /* if the visitor is logged in, this primary navigation will be displayed */
    } else {
        wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); /* if the visitor is NOT logged in, this primary navigation will be displayed. if a single menu should be displayed for both conditions, set the same menues to be displayed under both conditions through the WordPress backend */
    } ?>
</nav></div><!--#nav-primary-->

I know that the ‘header-menu’ is pointing to a new Menu I set up, but it’s not showing the correct one. Instead, it’s showing lots of menu items, when the one I set up has only 4 items.

Can anyone shed any light on this at all? I would really appreciate some help.

Thanks!

Mark

Related posts

Leave a Reply

1 comment

  1. Check this step.

    1. Have you added this function in function.php file. If no add this.

      /* Add two custom menu */

                  function register_my_menus() {
                    register_nav_menus(
                      array(
                        'logged-in-menu' => __( 'Logged in Menu' ),
                        'header-menu' => __( 'Header Menu' )
                      )
                    );
                  }
                  add_action( 'init', 'register_my_menus' );
      
    2. Have you selected menu from Appearance > Menu for both of your menu ? If no then create menu and select that.

    Let me know still you need any help.

    EDIT
    New code for logged in and not logged in use menu.

    /* Add two custom menu */ 
    function register_my_menus() { 
        register_nav_menus( 
            array( 'top-menu' => _( 'Top Menu' ), 
                'header-top-menu' => _( 'Header Top Menu' ) ) ); 
        } 
        add_action( 'init', 'register_my_menus' ); 
    
    
        <?php if ( is_user_logged_in() ) 
            { wp_nav_menu( array( 'theme_location' => 'top-menu' ) ); } 
            else { wp_nav_menu( array( 'theme_location' => 'header-top-menu' ) ); } 
            ?>