title: Wordpress: Walker Class: Trying to add dropdown arrow to nav menu
body: <p>Okay so I have a Walker class. I am trying to add a dropdown arrow ONLY TO the menu items that have SUB MENU.</p>
  
  <p>Arrow Icon: <code>&lt;br&gt;&lt;span class="nav-desc" id="nav-desc-show"&gt;&lt;i class="fa fa-caret-down" aria-hidden="true"&gt;&lt;/i&gt; &lt;/span&gt;</code></p>
  
  <p><strong>PROBLEM At the moment I have getting the arrow for every single menu item because im not sure how to change this so it shows for only menu items with sub menu.</strong></p>
  
  <p><strong>custom-primary-nav.php</strong></p>
  
  <pre><code>&lt;?php 
  
  class Nav_Walker_Nav_Menu 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 id="menu-item-'. $item-&gt;ID . '"' . $value . $class_names .'&gt;';
  
           /* adding the class name for sub menu custom - */
            // $output .= "\n$indent&lt;ul class=\"sub-menu-about\"&gt;\n";
  
  
         $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        ) .'"' : '';
  
  
         $description  = ! empty( $item-&gt;description ) ? '&lt;span&gt;'.esc_attr( $item-&gt;description ).'&lt;/span&gt;' : '';
  
  
  
          $item_output = $args-&gt;before;
          $item_output .= '&lt;a'. $attributes .'&gt;&lt;span data-hover="'. $item-&gt;title .'"&gt;';
          $item_output .=$args-&gt;link_before .apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID );
          $item_output .= $description.$args-&gt;link_after;
  
          /* Add span add in this nav menu - custom* */
          $item_output.= '&lt;br&gt;&lt;span class="nav-desc" id="nav-desc-show"&gt;&lt;i class="fa fa-caret-down" aria-hidden="true"&gt;&lt;/i&gt; &lt;/span&gt;';
  
          $item_output .= '&lt;/span&gt;&lt;/a&gt;';
          $item_output .= $args-&gt;after;
  
          $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Header.php</strong></p>
  
  <pre><code>&lt;?php
  /**
   * The header for our theme
   *
   * This is the template that displays all of the &lt;head&gt; section and everything up until &lt;div id="content"&gt;
   *
   * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
   *
   * @package radian3
   */
  
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html &lt;?php language_attributes(); ?&gt;&gt;
  &lt;head&gt;
      &lt;meta charset="&lt;?php bloginfo( 'charset' ); ?&gt;"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;link rel="profile" href="http://gmpg.org/xfn/11"&gt;
  
      &lt;?php wp_head(); ?&gt;
  &lt;/head&gt;
  
  &lt;body &lt;?php body_class(); ?&gt;&gt;
  &lt;div id="page" class="site"&gt;
      &lt;a class="skip-link screen-reader-text" href="#content"&gt;&lt;?php esc_html_e( 'Skip to content', 'radian3' ); ?&gt;&lt;/a&gt;
  
  
  
      &lt;header id="masthead" class="site-header"&gt;
          &lt;div class="header-wrap"&gt;
              &lt;div class="site-branding"&gt;
                  &lt;?php the_custom_logo(); /* Gets the custom logo */ ?&gt;
                  &lt;div class="site-branding-text"&gt;
                      &lt;?php if ( is_front_page() &amp;&amp; is_home() ) : ?&gt;
                          &lt;h1 class="site-title"&gt;&lt;a href="&lt;?php echo esc_url( home_url( '/' ) ); ?&gt;" rel="home"&gt;&lt;?php bloginfo( 'name' ); ?&gt;&lt;/a&gt;&lt;/h1&gt;
                      &lt;?php else : ?&gt;
                          &lt;p class="site-title"&gt;&lt;a href="&lt;?php echo esc_url( home_url( '/' ) ); ?&gt;" rel="home"&gt;&lt;?php bloginfo( 'name' ); ?&gt;&lt;/a&gt;&lt;/p&gt;
                      &lt;?php
                      endif;
  
                      $description = get_bloginfo( 'description', 'display' );
                      if ( $description || is_customize_preview() ) : ?&gt;
                          &lt;p class="site-description"&gt;&lt;?php echo $description; /* WPCS: xss ok. */ ?&gt;&lt;/p&gt;
                      &lt;?php
                      endif; ?&gt;
                  &lt;/div&gt;
              &lt;/div&gt;&lt;!-- .site-branding --&gt;
  
              &lt;nav id="site-navigation" class="main-navigation"&gt;
                  &lt;button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"&gt;&lt;?php esc_html_e( 'Primary Menu', 'radian3' ); ?&gt;&lt;/button&gt;
                  &lt;?php       
                      $walker = new Nav_Walker_Nav_Menu;
  
                      $args = array(
                          'theme_location' =&gt; 'primary',
                          'menu_id' =&gt; 'primary-menu',
                          'walker' =&gt; $walker
  
                      );
                      wp_nav_menu($args);
                  ?&gt;              
              &lt;/nav&gt;&lt;!-- #site-navigation --&gt;         
          &lt;/div&gt;
  
      &lt;/header&gt;&lt;!-- #masthead --&gt;
  
      &lt;div id="content" class="site-content"&gt;
  </code></pre>