You’ve not added a fallback_cb
key to the argument array. You also need to add a theme_location
key:
php start $menu = wp_nav_menu(
array(
'menu_class' => 'reset sf-menu',
'container_id'=>'nav',
'echo'=>0,
'fallback_cb' => 'mytheme_fallback_function' // ADD ME!!!
'theme_location' => `location_name` // ADD ME, AS DEFINED IN register_nav_menu()
)
);
$menu = str_replace("\n", "", $menu);
$menu = str_replace("\r", "", $menu);
$menu = str_replace("\t", "", $menu);
echo $menu;
php end
Alternately, you could wrap your code in an if ( has_nav_menu( 'location_name' ) )
conditional:
if ( has_nav_menu( 'location_name' ) ) {
echo $menu;
} else {
// Do something else, like wp_list_pages() or wp_page_menu()
}
Related Posts:
- Add Javascript to WordPress Menu
- Add custom menu item using wp_nav_menu_items filter
- Custom search filter causes menu and query_posts problems
- Add separator to admin submenu
- register_nav_menus() won’t register menus
- Custom Post Types posts as submenus in Nav Menu
- How do I add nested categories to drop-down menu in twenty-eleven?
- Add custom page link with anchor
- 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?
- add_action for saving a custom menu
- How to change Twenty Seventeen theme’s navigation bar location?
- Making WordPress’ page and menus visible only for logged in users, checking session variables
- How can I put two menus in the same div?
- Indirect modification of overloaded property WP_Post::$classes has no effect
- WordPress – site with 2 stylesheets and more…
- How to add a CSS class to the tooltip on a navigation menu?
- Top Menu showing as Plain text before page load [closed]
- Add a class to the body tag when a menu is enabled
- how to change the output of wp_nav_menu using css classes
- Auto add pages to primary menu with functions.php
- Manage custom menu for an Editor?
- How to get the name of the parent menu if the current page is an archive page in a custom menu
- How do I check menu slug in WordPress?
- vertical menu bar
- Add class active to static menu
- Update body class based on menu
- How to add fixed position in menu class for Twenty Twelve theme?
- How do I separate link levels in a custom menu walker?
- Possible Menu Hack?
- How to set my main menu items
- Allow users with Editor role to edit menus (without a plugin)
- Add custom links like functionality
- I need my dropdown sub-sub-menu box to show sub-menu title above
- Sorting child item of navigation menu using code in wordpress
- I want to hide the navigation menu on a particular page
- Difference between walker class and basic php
- Allowing HTML in Menu Descriptions
- How to add class to parent a tag with a sub menu
- Listing Child Pages in a Certain Order?
- 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
- Trying to add a custom social icon to a Twenty Twenty-One child theme
- How to hide a menu from public, but share content with a private link [closed]
- Navigation menu not visible (contrast issue) on home page
- Full screen nav menu block with avada theme
- functions.php adding item to end of menu. I want to change position
- WordPress menu>Custom Link: removing my link formatting and adding %20
- Custom Menu Anchor Links Not Working
- WordPress Menu Exchange for Mobile Layout
- Switching to child theme breaks menu names
- 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
- How to implement a secondary menu?
- Buggy wp_nav_menu?
- Styling issue with custom menus and sub menus
- 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
- Putting footer links into different columns
- WordPress nav_menu items from another menu appearing
- 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 Use Default Auto-Generated 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?
- Two questions about CSSing inside the menus
- Different menu on different category need advice
- Always show wordpress submenu on responsive header menu
- 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
- How to use my custom menus as seperate pages?
- Building Menus with the latest posts included
- Cannot control wp_nav_menu properly
- wordpress superfish dropdown menu
- Drop down menus css in custom menus
- WordPress wp get nav menu items does not deliver external link
- 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?
- How to replicate a mobile menu from a site to a wordpress site [closed]