wp_nav_menu not selecting teh correct menu

I'm having a weird issue. I have 2 menus, and registered them in functions.php, like this:

add_theme_support( 'menus' );
register_nav_menu( 'primary', 'Top Nav' );
register_nav_menu( 'footer', 'Footer' );

In my header, I have the following code

?php
    wp_nav_menu(array(
    'menu' = 'Top Nav',
    'theme_location' = 'primary',
    'depth' = 2,
    'container' = 'div',
    'container_class' = 'navbar-collapse collapse',
    'menu_class' = 'nav navbar-nav navbar-right',
    'fallback_cb' = 'wp_bootstrap_navwalker::fallback',
    'walker' = new wp_bootstrap_navwalker()
)); ?

However, the header always display the other menu, assigned to footer, no matter what I do. I tried using menu and theme_location alone, changing names, adding another location and assigning the menu to this new location, un-assigning the other menu and anything I could think of, to no avail. Nothing I do seems to work, exception made of deleting the other menu, which of course is not the idea since I want both of them.

Just in case, the footer menu is called like this

?php wp_nav_menu( array( 'theme_location' = 'footer' ) ); ?

Any idea on what am I doing wrong?

Topic navigation menus Wordpress

Category Web


I faced the same issue and finally got the answer:

For functions.php:

register_nav_menu( 'primary', __( 'Navigation Menu', 'Removemymug_Theme' ) );
register_nav_menu( 'second-menu', __( 'Second Menu', 'Removemymug_Theme' ) );

For Secondary Menu (Footer):

wp_nav_menu( array(
    'menu'            => 'second-menu',
    'theme_location'  => 'second-menu',
    'depth'           => 2,
    'container'       => 'div',
    'container_class' => 'navbar-collapse collapse',
    'menu_class'      => 'nav navbar-nav navbar-right',
    'fallback_cb'     => 'wp_bootstrap_navwalker::fallback',
    'walker'          => new wp_bootstrap_navwalker()
) );

For Top Navigation:

wp_nav_menu( array(
    'menu'            => 'primary',
    'theme_location'  => 'primary',
    'depth'           => 2,
    'container'       => 'div',
    'container_class' => 'navbar-collapse collapse',
    'menu_class'      => 'nav navbar-nav navbar-right',
    'fallback_cb'     => 'wp_bootstrap_navwalker::fallback',
    'walker'          => new wp_bootstrap_navwalker()
) );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.