• Resolved Norm

    (@casualmagic)


    Is there a known issue or practice around using wp_nav_menu() multiple times on the same page?

    I used it to call ‘menu’ => ‘Menu Name’ for three different menus in header.php and the second two would act as if the named menu didn’t exist. Also using Theme Location didn’t get the desired menu either. To be clear I am using 3 instances of wp_nave_menu(), I registered the menu locations in functions with register_nav_menus.

    I was able to call all three menus by getting the menu ID.

    I’m just trying to understand why this wasn’t loading.

    Also I think this question should go in WP Advanced but that forum is closed.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • ThemeSumo

    (@themesumo)

    How are you registering your menus, something like this?

    function my_custom_menus() {
        register_nav_menus(array(
            'my_menu_one' => esc_html__('Menu One', 'lang'),
            'my_menu_two' => esc_html__('Menu Two', 'lang')
        ));
    }
    add_action('after_setup_theme', 'my_custom_menus');

    You should then be able to call menus like so:

    <?php if (has_nav_menu('my_menu_one')) { ?>
        <nav class="my-custom-menu" role="navigation">
            <?php wp_nav_menu(array('theme_location' => 'my_menu_one')); ?>
        </nav>
    <?php } ?>

    Let me know if this works.

    • This reply was modified 8 years ago by ThemeSumo. Reason: Additional information
    Thread Starter Norm

    (@casualmagic)

    Thanks for your response. I am not putting the registration inside a function.

    register_nav_menus( array(
    	'main_menu' => 'Main Menu',
    	'footer_menu1' => 'Footer Menu 1',
    	'footer_menu2' => 'Footer Menu 2'
    ) );

    if has_nav_menu is working.

    Why wouldn’t just calling wp_nav_menu work? I’ve don’t it before.

    ThemeSumo

    (@themesumo)

    Try using the method I posted above, it should work without any issues.

    Navigation_Menus

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp nav menu multiple uses on same page’ is closed to new replies.