Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

An example custom menu structure I would like users to see

About 
Interests
- Movies
- Toys
- Fun
Job
Hangouts

The end result outputted menu ready for dropdownage would be

About
- Interests
  - Movies
  - Toys
  - Fun
- Job
- Hangouts

The way I have solved it for now is by filtering the wp_nav_menu_object

add_filter( 'wp_nav_menu_objects', 'add_menu_parent');

function add_menu_parent( $items ) {

  //grab the id of the first menu item
  $parent = $items[1]->ID;

  foreach ($items as $key => $object) {

   //if menu item has not parent and not the first item set the items menu parent to be the first item in the menu  
   if ($object->menu_item_parent === 0 && $object->ID != $parent){
      $object->menu_item_parent = $parent;
  }

 }
}

I'm wondering if there is a more robust way to do this with a custom walker class.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.