I am trying to add a wrapping div around a specific sub-menu.
what is the best way to do it ? is there a way to target the sub-menu and modify it or should i just use 'wp_nav_menu' or 'wp_nav_menu_items' filters and do some string manipulation to get this done ?

  • 1
    If by submenu you mean a separate Menu, you can just add a parameter on wp_nav_menu. But if by submenu you mean one part of a Menu, you would need to create a custom Walker that recognizes the particular submenu and outputs the extra div. But what do you need the extra div for? If it's just styling, you can view the source and there will be a way to target that particular submenu for styling purposes. – WebElaine Oct 30 '18 at 13:19
  • @WebElaine by submenu i mean menu items that are children of a menu item. and yes i need it for styling, and i guess what i'm trying to achieve can't be done without adding a wrapping div, actually i'm trying to create a full width mega menu with the menu items centered (like in bootstrap container). I've added the needed div using the walker. – Badr Oct 30 '18 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.