WordPress.org

Forums

[resolved] Wrong menu being displayed by wp_nav_menu() (3 posts)

  1. roganty
    Member
    Posted 1 year ago #

    Hi,
    Firstly I hope this is posted in the right forum!

    I'm creating my own theme and I've added menu support, but I'm having trouble with the wrong menu being displayed.

    In functions.php I have

    add_action( 'init', 'roganty2_menus' );
    
    function roganty2_menus(){
    
    	register_nav_menus(
    		array(
    			'main-menu' => 'Main Menu'
    		)
    	);
    
    }

    In header.php I have

    <?php wp_nav_menu( array('theme-location' => 'main-menu', 'container' => false, 'depth' => 1) ); ?>

    In the back end I have two menus, 'Long Menu' and 'Short Menu'
    I have selected 'Short Menu' to be in the 'Main Menu' location, but it only displays 'Long Menu'.

    The only way it displays 'Short Menu' is if I delete 'Long Menu'. As soon as I recreate 'Long Menu' it starts displaying 'Long Menu' again!

    Other things I have tried:

    1. Deleting cache
    2. Renaming 'Short Menu' to 'Main Menu'

    Has anyone got any ideas??

  2. roganty
    Member
    Posted 1 year ago #

    Ok, I've been testing this for a while now.
    All my other themes, when I select a menu, that menu is displayed!

    It's only with this one theme!!!!

    I've deleted all menus, and recreated them using different names, and still, only the first menu I created is the one used!! What the hell is going on!?

    I have checked my code against the other themes, and its the same!

    I've tried renaming the menu location.
    I've tried adding a second menu location.
    But still only the first menu is used!

  3. roganty
    Member
    Posted 1 year ago #

    I can't believe I've been so stupid!!

    It should be 'theme_location' with underscore!

    Doh!

Topic Closed

This topic has been closed to new replies.

About this Topic