0

As the title says, I'm using wp_nav_menu in header.php to load in the audience, secondary, and main menus and when I do, every menu contains every page - or at least many more pages than I selected for the menus.

I'm having the hardest time trying to make this work for some reason, so any help is appreciated. Here's the code to register the menus in functions.php:

// WordPress Menu Locations
function diviecommerce_setup() {
register_nav_menus(array(
    'primary' => esc_html__( 'Main Menu', 'diviecommerce' ),
    'audience' => esc_html__( 'Audience', 'diviecommerce' ),
    'secondary' => esc_html__( 'Secondary', 'diviecommerce' ),
    'footer ' => esc_html__( 'Footer', 'diviecommerce' ),
));
}
add_action('after_setup_theme', 'diviecommerce_setup');

And here's the code in the template:

<div class="top">
    <?php wp_nav_menu( array('theme_location' => 'audience', 'container_class' => 'audience' ) ); ?>
    <div class="header-right">
        <?php wp_nav_menu( array('theme_location' => 'secondary', 'container_class' => 'account-cart' ) ); ?>
        <?php et_show_cart_total(); ?>
    </div>
    </div>
    <nav><?php wp_nav_menu( array('theme_location' => 'primary', 'container_class' => 'main' ) ); ?></nav>

Here's what this code spits out in browser

2
  • 2
    In the Menu Settings at wp-admin → Appearance → Menus, did you check the option labeled "Automatically add new top-level pages to this menu"? Have you also confirmed your menus do not actually have those "every page" or duplicated pages? And are you sure you've assigned a menu to those theme locations like audience?
    – Sally CJ
    Jun 2 at 13:57
  • 1
    Expanding on Sally's last question, if a menu has not been assigned to a location, wp_nav_menu() calls to render that location default to falling back on a function which will use all available pages as menu content. See the fallback_cb argument of wp_nav_menu()
    – bosco
    Jun 2 at 19:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.