title: Walker Nav Menu alteration (with div)
body: <p>I am working on a custom menu system using the <code>Walker_Nav_Menu</code> function. I have nearly got it working but i cant get through a few barriers which i hope someone can assist on.</p>
  
  <p>What am i trying to achieve?:</p>
  
  <pre><code>&lt;nav id="menu"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/about-us"&gt;About Us&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;
              &lt;span&gt;Second Layer&lt;/span&gt;
              &lt;div&gt;
                  &lt;ul&gt;
                      &lt;li&gt;&lt;a href="/second-layer/second-layer/"&gt;Second Layer&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="/second-layer/blah-blah/"&gt;blah blah&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>What is it currently doing?:</p>
  
  <pre><code>&lt;nav id="menu"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/about-us"&gt;About Us&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/second-layer/second-layer/"&gt;Second Layer&lt;/a&gt;
          &lt;span&gt;&lt;/span&gt;
              &lt;div&gt;
                  &lt;ul&gt;
                      &lt;li&gt;&lt;a href="/second-layer/blah-blah/"&gt;blah blah&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>I am trying to get the menu so if menu item has child items, it places it within a span and add that menu item as the first item under.</p>
  
  <p>Here is what i have done with the <code>Walker_nav_menu</code></p>
  
  <pre><code>class Excerpt_Walker extends Walker_Nav_Menu
  {
        function start_el(&amp;$output, $item, $depth, $args)
        {
             global $wp_query;
             $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  
             $class_names = $value = '';
  
             $classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;
  
             $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
             $class_names = ' class="'. esc_attr( $class_names ) . '"';
  
             $output .= $indent . '&lt;li&gt;';
  
             $attributes  = ! empty( $item-&gt;attr_title ) ? ' title="'  . esc_attr( $item-&gt;attr_title ) .'"' : '';
             $attributes .= ! empty( $item-&gt;target )     ? ' target="' . esc_attr( $item-&gt;target     ) .'"' : '';
             $attributes .= ! empty( $item-&gt;xfn )        ? ' rel="'    . esc_attr( $item-&gt;xfn        ) .'"' : '';
             $attributes .= ! empty( $item-&gt;url )        ? ' href="'   . esc_attr( $item-&gt;url        ) .'"' : '';
  
  
             if($depth == 0)
             {
              $item_output = $args-&gt;before;
              $item_output .= '&lt;a'. $attributes .'&gt;';
              $item_output .= $args-&gt;link_before .apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID );
              $item_output .= $description.$args-&gt;link_after;
              $item_output .= '&lt;/a&gt;';
              $item_output .= $args-&gt;after;
  
              $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  
             }else if($depth == 1){
  
              $item_output .= $args-&gt;before;
              $item_output .= '&lt;a'. $attributes .'&gt;';
              $item_output .= $args-&gt;link_before .apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID );
              $item_output .= $description.$args-&gt;link_after;
              $item_output .= '&lt;/a&gt;';
              $item_output .= $args-&gt;after;
  
              $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  
             }
  
          }
  
          function start_lvl(&amp;$output, $depth) {
              $indent = str_repeat("\t", $depth);
              $output .= "\n$indent" . $item_output = "&lt;span&gt;" . $args-&gt;link_before .apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID ) . "&lt;/span&gt;" . "&lt;div&gt;&lt;ul&gt;\n";
          }
  
  
  }
  </code></pre>