You can change nav menu args via the wp_nav_menu_args
filter.
So let’s say you have a theme that does something like this…
<?php
wp_nav_menu(array(
'theme_location' => 'second_level',
'depth' => 2, // how many levels to show
// prolly some other stuff here
));
You can hook into wp_nav_menu_args
, check for the theme location, and set depth to be 1 and remove submenus.
<?php
add_filter('wp_nav_menu_args', 'wpse87565_change_depth');
function wpse87565_change_depth($args)
{
if (!empty($args['theme_location']) && 'second_level' === $args['theme_location']) {
$args['depth'] = 1;
}
return $args;
}
Related Posts:
- Change submenu markup
- Automatically Display Sub Menu
- insert an HTML element if there is a submenu only
- Add a Submenu from Another Submenu in a Custom Theme
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Adding an Arbitrary Link to the Admin Menu?
- Add custom menu item using wp_nav_menu_items filter
- Add custom classes to anchor in wp_nav_menu
- how to create a menu with all sub categories?
- Add separator to admin submenu
- On which hook should I be calling register_nav_menu(s)?
- Display only page specific sub menu items using Custom Walker
- Add custom html to last sub-menu item
- How do I add nested categories to drop-down menu in twenty-eleven?
- How to add ul class on nav
- Add a .last class to the last in each ul.sub-menu
- Multi Level Bootstrap Navigation Menu in WordPress
- Add class to top level menu item if it has multiple child levels
- How show sub menu only using wp_nav_menu()
- Show only 2nd level of navigation depending on active navigation
- Simple Navigation Walker – Wrapper-class around first sub-menu
- How to get a separate child menu?
- Exclude one item from wp_list_pages( $args );
- wp_nav_menu() loses ‘current-menu-*’ classes on single product page within category
- Show menu item description with line breaks
- Remove/Disable “Automatically add new top-level pages to this menu”
- How to drag multiple menu items at once in WordPress?
- Customizing the a tag with Semantic UI
- Which settings/options are saved on a theme-basis and how does this affect theme-switching?
- Put a wp_nav_menu inside another one
- How to make pages metabox display all hierarchy in menu admin?
- Add items to a menu dynamically
- Generate a Menu that displays all child pages of top level parent
- How can I add a sub menu to an existing navigation menu in WordPress?
- Custom Nav Walker sub-menu HTML construct
- Check if wp_nav_menu items have submenus
- Add div to specific sub-menu
- Automatically Add New Tags to Sub-menu
- Adding different classes to anchor in navigation menu
- Nav walker, bootstrap: Display 3rd level items under 2nd level
- WordPress Add javascript:void(0); to menu link item?
- how to only add a top-level admin menu without it creating a sub-level-menu
- how to automatically generate hierarchical menus from hierarchy of pages?
- Adding custom text in items titles from wp_nav_menu()
- Why is ‘nav_menu_item_args’ filter’s $item argument empty?
- Custom Walker for Walker_Nav_Menu
- Arrow down in menu not displaying
- Programmatically adding menu items function replicates in multiple menus
- Handling complex multi-level architecture / menu for large site
- Sub-Pages only of menu items in current branch using a custom menu
- Custom Nav Walker Displaying Values in Sub Menu
- Does WordPress create mobile menus automatically?
- Update Nav Menu Items Programmatically
- How to display dynamic content in start_lvl function
- wp_list_pages: only show subpages on the parent page?
- Menus like a CMS
- How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
- next_post_link() on custom menu structure
- Third level navigation class
- WordPress sub-menu items suddenly not showing
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- No “current-menu-ancestor” class added when browsing an archive page
- Programmatically create and place a nav menu in a theme location?
- Main Menu and Sub Menu Items for Footer
- How to construct a custom html for submenus
- Create search form in menu as in Twenty Fourteen theme
- Check if menu id = $specific_id – then insert specific
- Does loading of sub pages in menu cause load to the server?
- Show menu based on parent & ancestor
- Why is my menu not ordered properly?
- How to include a third level with wp_get_nav_menu_items function
- Hook for number of items in Appearance > Menus > CustomPostType > View All [duplicate]
- wp_nav_menu() with multiple Class
- Filter for Admin Nav Menus Drop Down
- Schedule Page to Menu [duplicate]
- How do you manage large menu hierarchies in WP?
- Single-level menu option? Another way?
- Update body class based on menu
- add_submenu_page function to show videos table
- Trying to Create Menu in WordPress
- How do I add recent posts to the menu?
- How to add ID attribute to each submenu?
- Hierarchical menu nesting problem with jQuery targetting
- From a page, is it possible to find entry’s “menu_item_parent”?
- Automatically list top level menu item child pages
- My menu bar dissapeared with autooptimize [closed]
- Highlight current post ancestor parent menu items
- How to retrieve parent menu item name of current submenu item
- current-menu-item class not working properly
- Cant add menu items with my theme
- Check if menu_item has children or has parent
- Add code to WordPress menu items by class
- How to override the theme home page?
- Creating a menu containing categories and authors
- How to remove menu installed in wp-admin by a theme? [closed]
- getting the current sub item out of total sub items in a given dropdown (custom walker)
- Show WordPress Menu On External Site
- Change hyphen/dash for vertical line in menu [closed]
- How should I build a custom menu walker for this setup?
- How to customize submenus isn wordpress theme [closed]