wp_nav_menu 在有子级的菜单后添加span

Published
May 11, 2022
浏览次数 :  0

/*
*
* Walker for the main menu 
*
*/
add_filter( 'walker_nav_menu_start_el', 'add_arrow',10,4);
function add_arrow( $output, $item, $depth, $args ){

//Only add class to 'top level' items on the 'primary' menu.
if('primary' == $args->theme_location && $depth === 0 ){
    if (in_array("menu-item-has-children", $item->classes)) {
        $output .='<span class="sub-menu-toggle"></span>';
    }
}
    return $output;
}

Top