因此,我正在学习定制步行器,并遇到了一些问题。我有一个定制的助行器。我遇到的一个问题是如何将类添加到<a>
start\\u el函数内部。相关代码如下所示:
/**
* Filter the HTML attributes applied to a menu item\'s anchor element.
*
* @since 3.6.0
* @since 4.1.0 The `$depth` parameter was added.
*
* @param array $atts {
* The HTML attributes applied to the menu item\'s `<a>` element, empty strings are ignored.
*
* @type string $title Title attribute.
* @type string $target Target attribute.
* @type string $rel The rel attribute.
* @type string $href The href attribute.
* }
* @param object $item The current menu item.
* @param array $args An array of {@see wp_nav_menu()} arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$atts = apply_filters( \'nav_menu_link_attributes\', $atts, $item, $args, $depth );
$attributes = \'\';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( \'href\' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= \' \' . $attr . \'="\' . $value . \'"\';
}
}
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( \'the_title\', $item->title, $item->ID );
/**
* Filter a menu item\'s title.
*
* @since 4.4.0
*
* @param string $title The menu item\'s title.
* @param object $item The current menu item.
* @param array $args An array of {@see wp_nav_menu()} arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$title = apply_filters( \'nav_menu_item_title\', $title, $item, $args, $depth );
$item_output = $args->before;
$item_output .= \'<a\'. $attributes .\'>\';
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= \'</a>\';
$item_output .= $args->after;
我觉得这样做的方法是通过传递带有$item\\u输出的新类,但我还没有找到如何做到这一点(代码是什么样子的)。
有什么想法吗?