Title: Add sub menu(drop)
Last modified: September 1, 2016

---

# Add sub menu(drop)

 *  [Atom90](https://wordpress.org/support/users/atom90/)
 * (@atom90)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/add-sub-menudrop/)
 * I create my theme. but i dont know how too add to menu sub menu.
    i Show how 
   it works In function.php
 *     ```
       function register_menus(){
       	register_nav_menus(
       		array( 'header-menu' => __('Main Menu'))
       	);
   
       }
       add_action('init', 'register_menus');
   
       //walker
   
       class description_walker extends Walker_Nav_Menu
       {
   
         function start_el(&$output, $item, $depth, $args)
         {
              global $wp_query;
              $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
   
              $class_names = $value = '';
   
              $classes = empty( $item->classes ) ? array() : (array) $item->classes;
   
              $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
              $class_names = ' class="'. esc_attr( $class_names ) . ' root"';
   
              $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
   
              $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
              $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
              $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
              $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
   
              $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
   
              if($depth != 0)
              {
                        $description = $append = $prepend = "";
              }
   
               $item_output = $args->before;
               $item_output .= '<a'. $attributes . 'class="orphan item bullet"' .'>';
               $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
               $item_output .= $description.$args->link_after;
               $item_output .= '</a>';
               $item_output .= $args->after;
   
               $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
   
                           if ($item->menu_order == 1) {
                   $classes[] = 'first';
               }
   
               }
       }
   
       add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
       function special_nav_class($classes, $item){
            if( in_array('current-menu-item', $classes) ){
                    $classes[] = 'active ';
            }
            return $classes;
       }
       ```
   
 * header.php
 *     ```
       <nav class="nav-main" id="">
   
       							<?php
       $defaults = array(
         'theme_location'  => 'header-menu',
         'menu'            => 'test',
         'container'       => false,
         'container_class' => '',
         'container_id'    => '',
         'menu_class'      => '',
         'menu_id'         => '',
         'echo'            => 'echo',
         'fallback_cb'     => 'wp_page_menu',
         'before'          => '',
         'after'           => '',
         'link_before'     => '',
         'link_after'      => '',
         'items_wrap'      => '<ul class="menutop level1" >%3$s</ul>',
         'depth'           => 1,
         'walker'          => '',
         'walker' => new description_walker()
       );
       wp_nav_menu( $defaults );
   
        ?>
       						</nav>
       ```
   
 * what i need more?

The topic ‘Add sub menu(drop)’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [Atom90](https://wordpress.org/support/users/atom90/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/add-sub-menudrop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
