i'm working on the new site with custom menu and extended Walker_Nav_Menu class to add custom content to the wp nav menu.
i have registered a custom select box (key: my_custom_menu) in menu from wordpress admin, have a look at the following image:
My question is: Is there any way to remove/exclude the submenu if the user use custom menu instead of multilevel submenu, example:
//conditional for parent menu item Contact us
if($menu_item->my_custom_menu !== 'none'){
//Remove all the nested submenu with depth != 0 (including <ul class="submenu">)
// so the expecting result is : remove all submenus inside Contact us .
}
i know there's a function called display_element() in Walker class but i dont know how to use it.
wp_get_nav_menu_items
to remove items from the menu, which integrates better with themes that might have their own custom walkers. I did that for my Nav Menu Roles plugin. I don't have time to write a full answer, but maybe the source code will help you.!is_admin()
conditional to avoid any deleterious effects on the admin side of things.