我会尽量简短。因此,基本上我正在尝试将自定义项添加到我的菜单中,在本例中,这是带有months desc的归档下拉列表.wp_get_archives
也会忽略所有css
function add_archive_dropdown($items, $args) {
if( $args->theme_location == \'primary\' ){
$items .=\'<li class="nav-item dropdown">\'
.\'<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\'
.\'Archive\'
.\'</a>\'
.\'<ul class="dropdown-menu" style="list-style:none;" aria-labelledby="navbarDropdown">\'
.\'<li>\'
.\'<a href="#">\'.\'August 2018\' .\'</a>\'
.\'</li>\'
.\'<li>\'
.wp_get_archives( array(\'type\' => \'monthly\', \'format\' => \'html\', \'show_post_count\' => $c))
.\'</li>\'
.\'</ul>\'
.\'</li>\';
}
return $items;
}
add_filter(\'wp_nav_menu_items\', \'add_archive_dropdown\', 10, 2);
结果:
最合适的回答,由SO网友:Dejan Arsenijevic 整理而成
解决方案:“添加”echo\' => false,
到参数数组!“@bcworkz不同wp论坛