• I’m having a very weird issue with creating multiple menu’s. I’ve performed all of the steps for creating multiple menu’s on a website, and have called them in my header file, one after the other, using the wp_nav_menu() function. However, after calling them, only firs menu appears, and it is repeated, regardless of what I place as the secondary menu. The only way I’ve gotten to this work appropriately is by declaring the actual names of the menu’s thru wp_nav_menu(array=’Menu Name’); But that only works if the menu is called “Menu Name”. I’m quite confused and feel as if I’m doing something very wrong here. here is my code snippits, and please tell me if I’m doing anything wrong in the way I’m declaring these two seperate menus.

    functions.php

    /* Menu Registration */
    add_action('init', 'register_my_menus');
    
    function register_my_menus() {
    	register_nav_menus(
    	array (
    		'primary' => __('Top Menu'),
    		'secondary' => __('Bottom Menu'))
    	);
    }

    header.php

    <?php wp_nav_menu(array('container' => 'div', 'container_id' => 'top-nav', 'menu_class' => 'nav', 'fallback_cb' => false, 'theme_location' => 'primary')); ?>
    <?php wp_nav_menu(array('container' => 'div', 'container_id' => 'second-nav', 'menu_class' => 'nav', 'fallback_cb' => false, 'theme-location' => 'secondary')); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t think you need add_action().
    Try this:

    functions.php

    if ( function_exists( 'register_nav_menus' ) ) {
      	register_nav_menus(
      		array(
      		  'foot_menu' => 'First Menu',
      		  'sidebar_menu' => 'Second Menu'
      		)
      	);
    }

    header.php

    <? wp_nav_menu( array('menu' => 'First Menu' )); ?>
    <? wp_nav_menu( array('menu' => 'Second Menu' )); ?>

    I just tested this on my WP installation and it worked nicely.

    I also noticed that if you don’t create menus with the same names used in wp_nav_menu( array('menu' => '[name here]' )) WordPress will show the same menu contents for each menu. So in my example above, so long as I created a menu named “First Menu” and another named “Second Menu” via the admin it would work properly.

    Thread Starter Leo Newball

    (@lnewball)

    What you mention (about the same menu contents for each menu) is the issue I’m having. Supposedly I don’t have to declare the menu name if I’m using theme_location=> 'location-defined-in-register_nav_menus' so, in theory, I should be able to swap out each menu without having to declare the menu name in wp_nav_menu( array('menu' => '[name here]' ))

    Your tip with removing add_action(); and calling the function directly seems to work however! Thanks Decavolt!

    Hi Inewball,
    1. Admin > Appearance > Menus
    2. Create a new menu for the ‘Primary Location’, add pages, posts, categories or links, and SAVE
    3. ‘Menu Locations’ and assign this menu to the ‘Primary Location’ and SAVE
    4. Create a new menu for the ‘Secondary Location’, add pages, posts, categories or links, and SAVE
    5. ‘Menu Locations’ and assign this menu to the ‘Secondary Location’ and SAVE

    HTH

    David

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Secondary wp_nav_menu repeating first’ is closed to new replies.