我必须补充itemprop="url"
导航栏中链接的链接this site.
在设置中,我找到了功能wp_nav_menu()
. 即使在阅读了WP codex之后,我也无法自己进行必要的更改。
代码如下:
<!-- BEGIN MAIN NAVIGATION -->
<nav class="nav nav__primary clearfix">
<?php if (has_nav_menu(\'header_menu\')) {
wp_nav_menu( array(
\'container\' => \'ul\',
\'menu_class\' => \'sf-menu\',
\'menu_id\' => \'topnav\',
\'depth\' => 0,
\'theme_location\' => \'header_menu\',
\'walker\' => new description_walker()
));
} else {
echo \'<ul class="sf-menu">\';
$ex_page = get_page_by_title( \'Privacy Policy\' );
if ($ex_page === NULL) {
$ex_page_id = \'\';
} else {
$ex_page_id = $ex_page->ID;
}
wp_list_pages( array(
\'depth\' => 0,
\'title_li\' => \'\',
\'exclude\' => $ex_page_id
)
);
echo \'</ul>\';
} ?>
</nav><!-- END MAIN NAVIGATION -->
这是Walker课程:
/*
* Navigation with description
*
*/
if (! class_exists(\'description_walker\')) {
class description_walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\\t", $depth ) : \'\';
$class_names = $value = \'\';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( \' \', apply_filters( \'nav_menu_css_class\', array_filter( $classes ), $item ) );
$class_names = \' class="\'. esc_attr( $class_names ) . \'"\';
$output .= $indent . \'<li id="menu-item-\'. $item->ID . \'"\' . $value . $class_names .\'>\';
// $attributes = ! empty( $item->attr_title ) ? \' title="\' . esc_attr( $item->attr_title ) .\'"\' : \'\';
// $attributes .= ! empty( $item->target ) ? \' target="\' . esc_attr( $item->target ) .\'"\' : \'\';
// $attributes .= ! empty( $item->xfn ) ? \' rel="\' . esc_attr( $item->xfn ) .\'"\' : \'\';
// $attributes .= ! empty( $item->url ) ? \' href="\' . esc_attr( $item->url ) .\'"\' : \'\';
$atts = array();
$atts[\'title\'] = ! empty( $item->attr_title ) ? $item->attr_title : \'\';
$atts[\'target\'] = ! empty( $item->target ) ? $item->target : \'\';
$atts[\'rel\'] = ! empty( $item->xfn ) ? $item->xfn : \'\';
$atts[\'href\'] = ! empty( $item->url ) ? $item->url : \'\';
/**
* Filter the HTML attributes applied to a menu item\'s <a>.
*
* @since 3.6.0
*
* @see wp_nav_menu()
*
* @param array $atts {
* The HTML attributes applied to the menu item\'s <a>, 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 wp_nav_menu() arguments.
*/
$atts = apply_filters( \'nav_menu_link_attributes\', $atts, $item, $args );
$attributes = \'\';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( \'href\' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= \' \' . $attr . \'="\' . $value . \'"\';
}
}
$description = ! empty( $item->description ) ? \'<span class="desc">\'.esc_attr( $item->description ).\'</span>\' : \'\';
if($depth != 0) {
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= \'<a\'. $attributes .\'>\';
$item_output .= $args->link_before;
if (isset($prepend))
$item_output .= $prepend;
$item_output .= apply_filters( \'the_title\', $item->title, $item->ID );
if (isset($append))
$item_output .= $append;
$item_output .= $description.$args->link_after;
$item_output .= \'</a>\';
$item_output .= $args->after;
$output .= apply_filters( \'walker_nav_menu_start_el\', $item_output, $item, $depth, $args );
}
}
}
最后的链接如下所示:
<li id="menu-item-2005" class="menu-item menu-item-type-post_type menu-item-object-page"><a itemprop="url" title="thetitle" href="http://thesite.com/about-us/">About Us</a></li>
我怎样才能做到这一点?