我想添加架构。组织机构SiteNavigationElement
以及导航栏链接的相对url属性。
我有以下几点:
<nav class="navbar navbar-default navbar-fixed-top" id="menu-nav" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<?php wp_nav_menu( array(
\'sort_column\' => \'menu_order\',
\'theme_location\' => \'header-menu\',
\'items_wrap\' => \'<ul class="menu-nav navbar-nav scroll-menu">%3$s</ul>\',
\'container_class\' => \'collapse navbar-collapse menu-header \'
) ); ?>
</nav>
我明白这一点
itemscope itemtype="http://schema.org/SiteNavigationElement"
应该转到
<nav>
. 那很好,我能做到。
但是,我如何添加itemprop="url"
指向导航栏的链接??
谢谢
最合适的回答,由SO网友:Tom J Nowell 整理而成
搜索一下我就知道了nav_menu_link_attributes
过滤器:
function wpse183311_filter( $atts, $item, $args ) {
$atts[\'itemtype\'] = \'http://schema.org/SiteNavigationElement\';
return $atts;
}
add_filter(\'nav_menu_link_attributes\', \'wpse183311_filter\', 3, 10);
将所需的属性添加到
$atts
根据需要排列