我一直试图在使用时只输出链接wp_nav_menu()
. 这是因为我有一个预定义的ul
和li
链接的标记。
这就是我所做的:
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="drop">
<?php
$args = array(
\'menu\'=>\'\',
\'menu_class\'=>\'\',
\'menu_id\'=>\'\',
\'container\'=>false,
\'container_class\'=>\'\',
\'container_id\'=>\'\',
\'theme_location\'=>\'header-menu\'
);
wp_nav_menu($args);
?>
</li>
相反,我得到的是:
<ul class="nav navbar-nav navbar-right">
<li class="drop">
<ul id="menu-header-menu" class="">
<li><a href="http://localhost/shalomcakes/home/">Home</a></li>
<li><a href="http://localhost/shalomcakes/theme/">Theme</a></li>
</ul>
在将此包含到
functions.php
:
function wp_nav_menu_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array(\'current-menu-item\')) : \'\';
}
add_filter(\'nav_menu_css_class\', \'wp_nav_menu_attributes_filter\', 100, 1);
add_filter(\'nav_menu_item_id\', \'wp_nav_menu_attributes_filter\', 100, 1);
add_filter(\'page_css_class\', \'wp_nav_menu_attributes_filter\', 100, 1);