The WordPress menu interface is a great way to manipulate navigation menus on your site. If you’re building a theme, however, you may find yourself wanting to limit the number of available sub-menu depths without removing the sub-menu items themselves.
You can style your way around it (styling .sub-menu .sub-menu
to act differently than .sub-menu
), you can use the wp_nav_menu
function’s depth argument to limit the depth, or you can use a custom Walker to force the output to match.
However, if your situation is such that the styling won’t work well and you want to limit navigation sub-menu depth, but not remove any menu items on lower depths (this happens with the depth argument in wp_nav_menu
), then the third option is the way to go: create a custom walker.
This removes all sub-menu wraps on sub-menus beyond the second level.
Featured image via Flickr CC, by Basheer Tome
Leave a Reply