0

I'm working on the working custom theme development where i need to add custom and additional class to the ul li a i have added extra class using CSS Classes (optional) but problem is that extra additional is not showing on the ul li a?

Walker_Nav_Menu

    class Desktop_Walker_Nav_Menu extends Walker_Nav_Menu
{
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
    {
        if (array_search('menu-item-has-children', $item->classes)) {
            $output .= sprintf("\n<li class='nw_submenu %s'><a href='%s' class=\"arrow_after\" >%s <i class='icon-angle-down' ></i></a>\n", (array_search('current-menu-item', $item->classes) || array_search('current-page-parent', $item->classes)) ? 'active' : '', $item->url, $item->title);
        } else {
            $output .= sprintf("\n<li class=\"nw_submenu\" %s><a href='%s'>%s</a>\n", (array_search('current-menu-item', $item->classes)) ? '' : '', $item->url, $item->title);
        }
    }

    function start_lvl(&$output, $depth = 0, $args = array())
    {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<ul class=\"nw_submenu_items\" role=\"menu\">\n";
    }
}

Menu Called In Header

  <?php 
  $defaults = array(
  'theme_location'  => 'header-menu',
  'container'       => 'ul',
  'menu_class'      => 'nw_menu nav navbar-nav navbar-right',
  'menu_id'       => '',    
  'walker'          => new Desktop_Walker_Nav_Menu()                                 
  );

  wp_nav_menu( $defaults );

  ?>

Problem Is Solved Now Here Solution Of It

class Desktop_Walker_Nav_Menu extends Walker_Nav_Menu
{
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
    {

         $classes     = empty ( $item->classes ) ? array () : (array) $item->classes;

        $class_names = join(
            ' '
        ,   apply_filters(
                'nav_menu_css_class'
            ,   array_filter( $classes ), $item
            )
        );

        ! empty ( $class_names )
            and $class_names = ' class="'. esc_attr( $class_names ) . '"';



        if (array_search('menu-item-has-children', $item->classes)) {
            $output .= sprintf("\n<li class='nw_submenu %s'><a href='%s' class=\"arrow_after\" >%s <i class='icon-angle-down' ></i></a>\n", (array_search('current-menu-item', $item->classes) || array_search('current-page-parent', $item->classes)) ? 'active' : '', $item->url, $item->title);
        } else {
            $output .= sprintf("\n<li class=\"nw_submenu\" %s><a $class_names href='%s'>%s</a>\n", (array_search('current-menu-item', $item->classes)) ? '' : '', $item->url, $item->title);
        }
    }

    function start_lvl(&$output, $depth = 0, $args = array())
    {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<ul class=\"nw_submenu_items\" role=\"menu\">\n";
    }
}

Your Answer

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