navigation - wp_nav_menu not selecting teh correct menu

admin2025-01-07  4

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?

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?

Share Improve this question asked Mar 10, 2015 at 23:44 ArielAriel 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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()
) );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255084a255.html

最新回复(0)