我正在尝试自定义wp中的菜单。我想添加<span></span>
仅限主菜单。但如果我这样做,它将应用于子菜单
也:
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= '<span></span>';
/** This filter is documented in wp-includes/post-template.php */
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
答案 0 :(得分:0)
Try something like this
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
if($depth>0){
$span='<span></span>';
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $span;
/** This filter is documented in wp-includes/post-template.php */
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;