The documentation is wrong. Check the source. There are two telling comments. First there is:
// Get the nav menu based on the theme_location
And after which there is another comment that reads:
// get the first menu that has items if we still can't find a menu
Following that last comment the code runs wp_get_nav_menus
and loops through every menu on the site hoping to find one that has associated items. In other words, wp_nav_menu
tries desperately to create a menu and will use the first one it finds. I don’t understand the logic behind that code. I get the concept of fallbacks, but this strikes me as fallback overkill.
You will need to wrap your code in has_nav_menu
to prevent this behavior.
if (has_nav_menu('nonsense')) {
wp_nav_menu(array('theme_location' => 'nonsense'));
}
Related Posts:
- Add Javascript to WordPress Menu
- Add custom menu item using wp_nav_menu_items filter
- Add separator to admin submenu
- register_nav_menus() won’t register menus
- Custom Post Types posts as submenus in Nav Menu
- Filter out built-in wp_nav_menu classes but keep custom class
- How to include the ‘current-menu-ancestor’ class on a custom post type menu in WordPress?
- HTML Bootstrap navigation menu to WordPress menu using wp_nav_menu
- Getting URL value from menu item by ID
- Adding a class (arrows) to main menu links that have children?
- Is it possible to add a filter for the output of nav-menu items in admin?
- Adding html elements to wp nav menu
- How to change menu according to the language?
- insert element inside wp menu list item
- WordPress Menu Disappears when $query->query_vars[‘meta_key’] is set
- How to style current page menu item when using a walker
- add_action for saving a custom menu
- Getting post content within wp_nav_walker
- Nav Walker current menu item not displaying
- Navigation (wp_nav_menu) refuses to nest within parent element
- Removing strip_tags not working on nav_menu_description
- Wp_Nav_Menu – Identify the last menu item
- Add custom menu item metabox in Navigation Settings
- Image as a link using wp_nav_menu()
- Hide Menu Unless Logged In
- Populating main menu from external JSON API
- HTML in Menu Items disappear on save
- How to put a Menu on the left side of a particular page in WordPress 3.5
- How to change theme header to support multiple nav menus?
- Unable to create or edit menus
- How to make link to different categories that in them selves loads different menus?
- How do you cope with the task of adding hierarchy to the navigation menu?
- wp-admin is blocking my mobile menu icon [closed]
- Filtering Only a Specific Menu using the “add_additional_class_in_li”?
- Displaying primary nav menu two ways
- Why do menus break on site url and folder change?
- Restrict control in nav-menu for specific role
- walker – 0 level on submenu formatting
- Translate a word in a responsive menu
- current-menu-item class not working properly
- Uber menu, manual integration, disable Mobile
- CSS_Menu_Walker not showing on mobile view?
- Remove nav menu item by script
- Drag and drop isn’t working while creating menu
- Custom Menu Broken WP 3.8.1 Update
- Why is only the first operation run in my loop – except for on the last repeat? [closed]
- WordPress + Bootstrap [closed]
- wp_nav_menu action/filter help
- How to hide a menu from public, but share content with a private link [closed]
- Full screen nav menu block with avada theme
- WordPress menu>Custom Link: removing my link formatting and adding %20
- URL links consistent with menus?
- WordPress Menu Exchange for Mobile Layout
- Wp_list_pages not showing children with custom page template
- How to check if current page is a parent item or child item in a given menu
- changing the labels inside appearance -> menus for some for the fields
- Lost admin “manage_link” capability WordPress. No “Links” menu item in admin menu
- How to implement a secondary menu?
- Buggy wp_nav_menu?
- dropdown menu, with walker
- Add function to custom menu
- When I click a custom menu link, how do I make it update the URL in the browser to the external link?
- Disabling tooltip on menu items
- Divide Menu into Separate Menus and Display them Side by Side
- Hook or callback when wp_nav_menu() has completed
- if role is logged in then do something
- Set one or more menus as a submenus of another menu
- How to show submenu of any page in main menu
- WP Menu Rollover Nav Item and Effect DIV Elsewhere
- Custom menu with additional logic for display
- Menu item that hides when you click the previous submenu
- Putting footer links into different columns
- How to create a mobile menu full screen overlay using Understraps Bootstrap 4 theme
- adding drop down menu item to existing menu
- wordpress walker add class to submenu a href
- Display searchform in the menu
- How to Hide/Remove Pages section in Menus (Dashboard)
- Unable to remove page from primary menu
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- wp-nav menu with custom walker , how to remove a tag if it has any submenu
- How to add a toggle on the left side of my page?
- Different menu on different category need advice
- Always show wordpress submenu on responsive header menu
- add custom entries to menu options
- Is there any way to recover deleted menu from database sql backup
- Showing a link with Javascript based on log-in status
- Placing generated list into drop-down on custom menu
- Building Menus with the latest posts included
- Cannot control wp_nav_menu properly
- How to add drop down sub menu from database fields in the particular menu slug
- wordpress superfish dropdown menu
- Drop down menus css in custom menus
- wp_nav_menu changed to wp_page_menu
- how to assign an ID to a wordpress menu
- Keeping my Sub Menu open when hovering on its list items
- How to change the markup created by menu item only on chosen items?
- How to disable permalink of a particular menu item?
- One item on menu is not clickable when it should be
- Critical Error when editing menu
- I need to change the hyperlink attached to the logo on the mobile menu