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 classes to anchor in wp_nav_menu
- how to create a menu with all sub categories?
- Display only page specific sub menu items using Custom Walker
- Add a .last class to the last in each ul.sub-menu
- Multi Level Bootstrap Navigation Menu in WordPress
- Simple Navigation Walker – Wrapper-class around first sub-menu
- 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
- How to make pages metabox display all hierarchy in menu admin?
- Custom Nav Walker sub-menu HTML construct
- Automatically Add New Tags to Sub-menu
- 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?
- Custom Walker for Walker_Nav_Menu
- Handling complex multi-level architecture / menu for large site
- Does WordPress create mobile menus automatically?
- How to display dynamic content in start_lvl function
- Menus like a CMS
- next_post_link() on custom menu structure
- Third level navigation class
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- Check if menu id = $specific_id – then insert specific
- How to include a third level with wp_get_nav_menu_items function
- 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?
- Trying to Create Menu in WordPress
- Hierarchical menu nesting problem with jQuery targetting
- Automatically list top level menu item child pages
- Cant add menu items with my theme
- Add code to WordPress menu items by class
- How to override the theme home page?
- How to remove menu installed in wp-admin by a theme? [closed]
- How should I build a custom menu walker for this setup?
- How to customize submenus isn wordpress theme [closed]
- Header and nav menu problem on Thesis site [closed]
- Switch from hover to click on Twenty Twelve Menu
- Admin: sub menu doesnt display under apperance when activate my themes
- a better menu, menu options assistance for WP
- How to override menu markup?
- Can I have a different menu for each parent page?
- remove class “sub-menu” from wordpress drop down menu
- Add a submenu to wp_nav_menu
- Wrap list parent in div with wp_nav_menu menu
- Insert a div class inside wordpress menu
- How to get menu location in wp_update_nav_menu hook
- Want to add different text after each menu item
- Is there a hook for nav menu item links to add custom css programatically?
- sub menu link is not working
- How to hide the menu item created by the theme in WordPress admin panel?
- How to get submenu of admin menu?
- How to Add support for sub-menu item description in wordpress?
- Add menu headings to WordPress sub menus
- Dropdown primary navigation menu not working
- Efficient wp mobile menu
- Link after WordPress
- cannot get global $menu value in form request
- Show Sub Menu on click and not hover
- wp_nav_menu container style args
- Structuring Nav Menu and Background Custom page (Help)
- Bootstrap Theme Migrated to WordPress
- Theme: dropdown hover menu not showing up in IE/Edge
- How can I click the parent menu then redirect to a special URL?
- Menu doesn’t open on mobile
- Creating navigation out of specific IDs and their children?
- I can´t make the menu unclickable in an easy way
- Generate Submenu based on Parent Page using If Statement
- Making my main menu a hamburger menu on all platforms
- menu change after theme change
- Product categories are mixed when creating menu
- Displaying a part of a menu containing the page the user is currently viewing and only it’s immediate children
- how to create pages and link them to a menu
- menu mobile show up even i in desktop mode in Newspaper Theme
- How to separate sub-menu output and keep associated with parent
- Show Child of Parent Page including all other parents
- wp_nav_menu in 3.7 add name class nav navbar-nav
- How to create a menu super voice in WP?
- Display all submenus
- Change sub-menu css class
- Adding Sub Menu In a theme which Do not have Menu Options
- ID of parent Menu
- Customizing Responsive Themes Menu [closed]
- Some informations about the use of statics pages in WordPress
- How can I alter the visible menu according to which level I am on [closed]
- How to display a submenu as a popup when clicking a button?
- how to mage the submenu open on wordpress active page
- Display sub menus as separate lists
- How can I added the post’s Categories to the site’s top menu (like a page)?
- What is the best way to incorporate responsive dropdown navigation menu into custom theme?
- Give custom class names to WP nav sub-menu