Title: register_nav_menu() issue
Last modified: August 19, 2016

---

# register_nav_menu() issue

 *  [bandicootmarketing](https://wordpress.org/support/users/tinkerpriest/)
 * (@tinkerpriest)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/)
 * I am testing out the nav menu function in 3.0-beta2-14769 and it is pretty cool.
   I came across something that might be a bug and I am not too sure how I am suppose
   to go about it so I am posted it here. (Please let me know if I am in the wrong
   place.)
 * I have registered two menus in my theme using the following code:
 *     ```
       register_nav_menu('main', 'Main Navigation Menu');
       register_nav_menu('sub', 'Sub-Navitation Menu');
       ```
   
 * When calling the registered menu within the `wp_nav_menu()` function, I use the`
   theme_location` argument. It works perfectly if both menu are created and assigned
   to each registered menu location.
 * If there are no menus, the `fallback_cb` argument allows me to create a function
   to set a default state, which is great.
 * The problem occurs if no menu is assigned to a specific registered menu location.
   If only one menu has been created, both locations display it whether it was assigned
   to that location or not.
 * I looked at the `nav-menu-template.php` file and it seems that the process for
   getting the nav menu works like this:
 *     ```
       1. Get the nav menu based on the requested menu name
       2. If no menu, get the nav menu based on the theme_location
       3. Get the first menu that has items if we still can't find a menu
       4. If a menu exists, get its items
       5. If no menu was found or if the menu has no items, call the fallback_cb
       ```
   
 * If a menu has been registered and no menu has been assigned to it, it seems like
   it should default to the `fallback_cb` as opposed to `get the first menu that
   has items`.

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [bandicootmarketing](https://wordpress.org/support/users/tinkerpriest/)
 * (@tinkerpriest)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507664)
 * I messed around with `nav-menu-template.php` and figured out a super simple solution,
   but I am not sure if it now works the way you guys intended.
 *     ```
       Line 208 in nav-menu-template.php
   
       	// get the first menu that has items if we still can't find a menu
       	if ( ! $menu ) {
       		$menus = wp_get_nav_menus();
       		foreach ( $menus as $menu_maybe ) {
       			if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) {
       				$menu = $menu_maybe;
       				break;
       			}
       		}
       	}
   
       Change it to:
   
       	// get the first menu that has items if we still can't find a menu
       	if ( ! $menu && !$args->theme_location) {
       		$menus = wp_get_nav_menus();
       		foreach ( $menus as $menu_maybe ) {
       			if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) {
       				$menu = $menu_maybe;
       				break;
       			}
       		}
       	}
       ```
   
 *  [Ryan Boren](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507691)
 * Looking into this for [ticket 13378](http://core.trac.wordpress.org/ticket/13378).
 *  [Ryan Boren](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507696)
 * Thanks for the patch. [Committed](http://core.trac.wordpress.org/changeset/14793).
 *  Thread Starter [bandicootmarketing](https://wordpress.org/support/users/tinkerpriest/)
 * (@tinkerpriest)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507699)
 * Awesome! Is there a better way to go about submitting bugs I find? I am going
   to be working with the latest beta version to update all of my premium themes
   and I might encounter some other issues.
 *  [Mr Papa](https://wordpress.org/support/users/usermrpapa/)
 * (@usermrpapa)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507700)
 * [http://core.trac.wordpress.org/](http://core.trac.wordpress.org/)
 * submit tickets there…
 *  [silvergrad](https://wordpress.org/support/users/silvergrad/)
 * (@silvergrad)
 * [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507764)
 * If I may ask, how DID you use wp_nav_menu? I have code like this:
 *     ```
       register_nav_menus( 'main_menu' , __( 'Main Menu', 'silvergrad' ));
       register_nav_menus( 'sub_menu' , __( 'Sub Menu', 'silvergrad' ));
       ```
   
 * and:
 * `wp_nav_menu('theme_location=sub_menu&container=&menu_class=menu_sub');`
 * That unfortunately doesnt work, it uses the callback function. Any ideas? I know
   that the theme_locations have been set properly.
 * Thanks!
 * EDIT: Never min, I figured it out. Was using old `register_nav_menu<strong>s</
   strong>()` code.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘register_nav_menu() issue’ is closed to new replies.

## Tags

 * [3.0](https://wordpress.org/support/topic-tag/3-0/)
 * [menu system](https://wordpress.org/support/topic-tag/menu-system/)
 * [nav menu](https://wordpress.org/support/topic-tag/nav-menu/)

 * In: [Alpha/Beta/RC](https://wordpress.org/support/forum/alphabeta/)
 * 6 replies
 * 4 participants
 * Last reply from: [silvergrad](https://wordpress.org/support/users/silvergrad/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/register_nav_menu-issue/#post-1507764)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
