This solution was shared by @TheDeadMedic over here…
$menu_exists_and_has_items = wp_nav_menu(
array(
'theme_location' => 'example-menu-location',
'container_class' => 'example-menu-container',
'menu_class' => 'example-menu-class',
'fallback_cb' => false,
'echo' => false
)
);
if ( $menu_exists_and_has_items ) {
...
Importantly, note that the menu is not echoed in the initial array saved to PHP variable…
Related Posts:
- Retrieving a list of menu items in an array
- Add Javascript to WordPress Menu
- Add custom menu item using wp_nav_menu_items filter
- Custom Post Types posts as submenus in Nav Menu
- Filter out built-in wp_nav_menu classes but keep custom class
- How to get a different mobile menu than desktop menu in the twentytwelve child theme
- Getting URL value from menu item by ID
- Adding html elements to wp nav menu
- Bar separated navigation by extending Walker_Nav_Menu
- insert element inside wp menu list item
- WordPress Menu Disappears when $query->query_vars[‘meta_key’] is set
- how do I delete (not exclude) a menu item from navigation bar
- show only a given level in nav menu
- How to style current page menu item when using a walker
- Anchor only wp_nav_menu
- Getting post content within wp_nav_walker
- Nav Walker current menu item not displaying
- Removing strip_tags not working on nav_menu_description
- Keeping ‘current-menu-item’ highlight of navigation menu?
- Hide Menu Unless Logged In
- Possible to add a dynamic link to a sub-menu via wp_nav_menu_items?
- HTML in Menu Items disappear on save
- Fragment URL in navigation item without a custom link
- How to change theme header to support multiple nav menus?
- Unable to create or edit menus
- 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?
- How to Implement Submenu Using wp_nav_menu
- Close dropdown menu on click or scroll outside the menu [closed]
- walker – 0 level on submenu formatting
- Translate a word in a responsive menu
- current-menu-item class not working properly
- Is there no straightforward way to display a separate second level using wp_nav_menu()?
- Uber menu, manual integration, disable Mobile
- CSS_Menu_Walker not showing on mobile view?
- Drag and drop isn’t working while creating menu
- Make pages visible to only logged in members
- Adding sub-menu item makes parent item unclickable
- Reverse the order of and in a wp_nav_menu
- Get custom classes in WordPress Navigation Menu
- Where is the order of a menu saved in the database
- how to remove description from menu buttons?
- Prevent more than 2 level menus in dashboard?
- Remove a class from a using Walker
- How can I create a new menu item that links to an archive of a custom post type?
- Make two bootstrap menus collapse into one dropdown
- How to convert the argument of wp_list_pages to an array
- How can I list the current pages siblings and any ancestor page siblings?
- Adding archive years to my menu
- Can you add shortcode as a menu item link?
- Replace anchor tag with span tag
- Show menu only if_page is
- Add a string after each item in WordPress sub menu
- Add # to submenu URLs automatically
- Custom menu – different submenu for first menu item
- switching test to production > main menu forgotten, background forgotten
- Automatically Generated Menu pages
- Costum walker with sub menu item count
- custom menu widget where menu title is a link
- removing the list container from the custom menu output
- creating a dynamic menu in wordpress
- Unable to nest categories in menu
- adding pages in underscores.me theme
- Hide default menu items in wordpress apearance > menus
- No option to move blocks up and down. The bar for it simply isn’t there
- Multi-Level Nav Bar
- How to make Logout Link consistently appear on all web pages?
- Header Navmenu glitching in Chrome (but not other browsers)
- Change markup for just 2nd list element in custom Walker menu
- Additional CSS for the nav menu
- Conditional hiding of the menu
- Incorrect Behavior on WordPress Main Menu
- Put two menus in the same location
- Custom wordpress submenu
- Secondary Menu display Primary Menu
- Mark a page of a queried menu as active
- Is it possible to separate all submenu items?
- Frontside menu based on custom roles logged in permission
- WordPress menus – automatically generate
- wp_nav_menu not selecting teh correct menu
- Menu item hidden behind others
- Admin Custom Menu Editor Disappeared
- Hide menu theme location for certain capabilities?
- Add a Submenu from Another Submenu in a Custom Theme
- Give a condition to a wordpress menu item to change its offerid for each landing page I create
- Highlighting Main Navigation Menu With Two or More Class Matches
- Display a tag before the menu list content
- Making a Custom Menu Sidebar Icon show as Current in css [closed]
- Adding two submenus to a menu
- Show different menus for login / logout user [closed]
- collapse twenty twelve submenu in mobile version
- Add custom ID to wp_nav_menu list items
- Problem with float:left – unexpected behavior [closed]
- Creating an accordion style menu
- Twenty-Twenty-Two Child Theme Mega Menu
- register_nav_menus() not registering
- Moving active menu item onscreen for mobile
- Remove WordPress Menu Classes and ID with Bootstrap Walker