Customize menu
-
Hi. I have this to codes for menu
1.class MY_Walker_Nav_Menu extends Walker_Nav_Menu { public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { $class_names = join( ' ', $item->classes ); $class_names = ' class="' . esc_attr( $class_names ). '"'; $output.= '<li id="menu-item-' . $item->ID . '"' . $class_names . '>'; $attributes = ''; $attributes.= !empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : ''; $item_output = $args->before; if($args->walker->has_children) { $item_output.= '<div class="header__menu-top"><a' . $attributes . '>' . $item->title.'</a>'; } else { $item_output.= '<a'. $attributes . '>' . $item->title . '</a>'; }; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<button class='header__menu-toggle-children'></button></div><ul class='sub-menu'>\n"; } public function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } }
and the second
2.
function my_nav_description( $item_output, $item, $depth, $args ) { if ( 'primary' == $args->theme_location && $item->description ) { $item_output = str_replace( $args->link_after . '</a>', '<div class="menu-item-description">' . $item->description . '</div>' . $args->link_after . '</a>', $item_output ); } return $item_output; } add_filter( 'walker_nav_menu_start_el', 'my_nav_description', 10, 4 );
So, the question is HOW can I combine them into one code? Is it possible?
And one more – how can I add
<button class='header__menu-toggle-children2'></button>
only for submenus? Now<button class='header__menu-toggle-children'></button>
button appears for first level menus and for all submenus.I need class
header__menu-toggle-children2
for submenu’s buttons andheader__menu-toggle-children
for first level.Result I want to achieve https://pastebin.com/vaeAjpRw
Thanks.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Customize menu’ is closed to new replies.