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>
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 likeaudience
?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 thefallback_cb
argument ofwp_nav_menu()