You can check the depth using the $depth
parameter to see if you are at the section level, and only add the <section>
based on that parameter.
function start_lvl(&$output, $depth = 0, $args = array()) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent";
if ( 2 == $depth ) {
$output .= "<section>";
}
$output .= "<ul class=\"sub-menu\">\n";
}
Replicate that with the end level and you can successfully make sure that the section only is present at the second depth.
Related Posts:
- Mega Menu Walker
- Add login hyperlink to secondary navigation menu
- start_lvl Ignored in Custom walker_nav_menu
- Displaying Logged-In User Name in WordPress Menu
- Logout and redirect using the WP Menu
- Run a filter when a walker runs
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically adding new post categories to menu
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- Nav-Menu not showing up
- Add parent menu item in sub-menu in custom nav_walker
- Add the “.current-menu-item” class to tag?
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Hide main div if wp_nav_menu is empty
- Check if a menu is empty?
- How to remove a metabox from menu editor page?
- Walker class: Problems with understanding how walk() method can be called without error
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to add active class to custom menu using while loop and wp_list_pages
- WordPress menu deletes when trying to add a hook
- Second Navigation inside header
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- items_wrap not working
- Style wp_page_menu() items
- Have CSS Class Added with `is_page()` WP function
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Can’t extend some core classes
- Change Navigation Bar based on logged in or not
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- How do I create page navigation linking to each H2 within the page? [closed]
- Multiple WordPress Menus that will only display all pages
- Menu — How to add “current-menu-grand-ancestor” css class
- WP Walker using custom css classes
- Menu Limitations
- Add data attribute to each li in menu
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Trying to store submenu items to render out after main menu
- How to change menu order item
- Add item to top of menu using a filter in functions.php
- Register a menu – Error Header
- How to style one item from main navigation?
- New walker for walker_nav_menu to change inside container data
- Add value to new attribute inside WordPress menu items
- Menu Custom Data Attributes
- How to display different submenus?
- Get the name of menu item with wp_nav_menu
- How to modify mobile nav menu text in theme
- How to add aria role and schema markup to custom walker container
- How can I use custom menus with a Bootstrap WordPress theme?
- Extend Menu Walker Output
- Custom navigation menu with awsAccordion
- Why can’t I add a custom image in my navigation?
- Remove submenu item from list
- Dynamic Menu drops pages?
- Remove the Tag from wp_nav_menu
- Menu not styling. New menus functionality giving me a headache
- Nav Walker that shows only children and siblings of top level parent menu item
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- Adding markup to sub menu based on class
- I want to show cart items number if any or nothing, simple CART text
- How to set Nav as a default menu in wordpress
- How to put 2 php codes in functions.php without site crashing
- Menu not updating for logged in users after redirect
- Redirect User when they click Menu Option
- Add element after navigation element title don’t works like I expect
- Difference between “Walker_Nav_menu” and “walker”
- How to create a sub-page of sub-page?
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Pulling a variable into the wp_nav_menu function
- How I can add div to menu?
- WordPress adding in site URL to header links
- Custom Links in Walker Class
- Nav Menu Display
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- Open WordPress Page from selected option dropdown
- How to add different menu items on different menus?
- Nav menù doesn’t display selected pages
- Cleaning up WordPress to improve performance?
- Adding Post Counts to Menu (Nav) Programmatically?
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- linking stylesheets and scripts with functions.php
- Class for Selected Menu using wp_nav_menu
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- How to output the taxonomies that are assigned to each custom post?
- Display current user metadata on WordPress page
- What is wrong in this code?
- wp_nav_menu prints children with parent name
- WordPress 2014 Theme – Featured Content with multiple tags?
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- Understanding responsive imagery
- How to get meta box labels?