So you are working on WordPress menu and you are stuck on one step and you can’t to figure out how to make this work.

  • Custom WP

You want to apply class just to first level of submenu? No worries, all you need to do i to copy and paste this code in your function.php theme file.


class Navwalker extends Walker_Nav_Menu {

    public function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent  = str_repeat( "\t", $depth );
        $output .= "\n$indent
    \n"; } public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat( "\t", $depth ); if($depth == 0) $output .= "\n$indent
      \n"; else $output .= "\n$indent
        \n"; } public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){ if(in_array("has_children", $item->classes)) { $output .= ""; } $output .= ""; } public function end_lvl (&$output, $depth = 0, $args = array()) { $output .= "
      "; } }>

Custom Function Custom WordPress Menu
Menu