best and easy way to hide submenu is to use css
.sub-menu {
display: none !important;
}
Or you can use ‘depth’=>1
`wp_nav_menu( array( 'menu_id'=>'nav', 'theme_location'=>'header-menu' , 'depth' => 1) );
or create a function to set the ‘depth’=>1 for a perticular menu. place this code in your theme function.php
add_filter( 'wp_nav_menu_args', 'remove_my_header_dropdown', 1, 1 );
function remove_my_header_dropdown( $args )
{
//lookup theme_location ie: top-menu
if ( isset( $args['theme_location'] ) && 'top-menu' ==
$args['theme_location'] ) {
$args['depth'] = 1; //levels of the hierarchy are to be included
}
return $args;
}
`
Hope that works for you
Related Posts:
- Split up wp_nav_menu with custom walker
- Error “Trying to get property of non-object” with Custom Walker for wp_nav_menu
- How to count nav menu items?
- Does Extending Multiple Nav_Menu_Walkers Allow Nested Menus?
- Display only page specific sub menu items using Custom Walker
- WordPress Menu Custom Walker Class
- Call custom field into menu item
- Determine if a navigation item has children
- Add Page ID class to nav menu items
- Pass a parameter to a menu walker
- Custom nav walker with different output depending on depth
- Bar separated navigation by extending Walker_Page
- Output the aria-labelledby parameter for a nav menu child
- Custom Nav Walker sub-menu HTML construct
- Customizing a walker menu class
- How to add ID and class in nav menu walker?
- How to remove trailing tags from wp_nav_menu walker
- How to add parent element’s title to nav menu’s child?
- `start_el` depth argument in custom nav walker always evaluates to zero
- Custom Walker anchor tag not inheriting attributes
- Check what “type” a menu item is
- How to display dynamic content in start_lvl function
- Add custom text to menu
- How to add a tag to wp_nav_menu in a child theme
- Adding post excerpt into navigation menu
- Use wp_nav_menu to display ALL pages
- Third level navigation class
- Editing WordPress Nav Menu Walker
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- How can I add divs or change li in the submenu of the menu_nav
- Get number of root elements in walker class
- Get top items number from wordpress menu
- add span class and i tag inside wp_nav_menu link anchor tag
- How to Overwrite/Customize wp-admin/nav-menus.php in WordPress
- Use menu class in walker function
- Add within the output of
- wp_list_pages() but only show children on the branch you are on
- Walker class conditional based on parent menu item label or custom css class
- How to create this Custom Walker Menu
- Sub Menu does not display using Nav Walker
- Is this format possible with a custom Nav Walker class?
- Put class on instead li
- Get Menu Name inside walker
- WordPress Menu Walker: add #hashes to child page links (only)
- WordPress Walker – Group two items?
- Where to implement custom walker class?
- custom walker class
- wp_nav_menu add class to child item with sub child
- How do you add a around the second level of a Menu?
- Page content loading issue using Walker_Nav_Menu
- creating a custom walker class
- Walker Class – Check if menu item has description and if so add class to li
- Dynamic_sidebar inside wp_nav_menu
- How to add attribute in menu code
- How to remove dropdown from wp_nav_menu
- How Do I Add Images To Main Navigation Menu
- Walker menu not displaying at all
- Wrapping link and .sub-menu with wp_nav_menu
- How to add a element with walker menu right after begin of the navigation tags?
- wp_nav_menu check both hierarchy fail?
- WordPress Nav Walker – Top menu link with dropdown link not clickable (dropdown opens)
- Adding a unique ID to each sub-menu
- Add custom class to li element which has children
- Custom menu walker – remove li tag based on class name
- Show Sidebar Menu Subpages When Clicking Parent
- How can I make wp_nav_menu() support tags?
- How to Add support for sub-menu item description in wordpress?
- How to add scroll IDs to WordPress menu anchors
- custom walker class for own menu?
- Adding a tag to wp_nav_menu
- Walker_Nav_Menu creating too many closing tags?
- Help with WordPress Custom Nav Walker
- Why is my navigation in my onepage not working?
- Is it possible to get_the_post_thumbnail (Featured Image) inside a sprintf function?
- WordPress menu walker – help to add custom class for each submenu
- Need help with Walker_Nav_Menu class
- why are my walker menu is showing like this?
- What is inside in $item in start_el function in Walker_Nav_Menu class
- Does the Default theme of WordPress like 2016, 2017 and 2019 uses Walker_Nav_Menu Class
- Where to place a svg chevron down in my custom walker?
- Add active class to wp_nav_menu
- Output existing wp_nav_menu with a custom walker
- Classes CSS (Optional) – how do I reference this in php?
- Displaying a part of a menu containing the page the user is currently viewing and only it’s immediate children
- Cannot add home page url to menu with #
- Show post titles within WordPress bootstrap Dropdown menu
- Add parent link to its submenu
- Creating custom Menu for custom theme
- Count Level 1 Childs for Custom Nav Walker WordPress
- Add dynamic content block to nav section generated by custom walker
- Need direction on a seemingly complex menu walker for automatically inserting a parent link li in it’s submenu ul
- Additional class for.sub-menu UL?
- How can I modify wp_nav_menu with walker?
- Walker for menus
- Use wp_nav_menu to dynamically generate child menus
- how to make a walker to this (in bootstrap, i try but not work)
- Broken drop down menu using Bootstrap and navwalker class
- how can i get the page_ID in nav li [closed]
- Custom navigation / menu output (walker?)
- Using walker to display all menu branches at once?