header.php
/*Render menu*/
<div class="main-nav">
<?php wp_nav_menu(
array(
'theme_location' => 'header-menu', 'container' => 'ul', 'menu_class' => 'nav'
)
);
?>
</div>
functions.php
/*Register menu*/
function register_main_menu(){
register_nav_menus(array(
'Primary' => __('Header Menu'), 'Footer' => __('Footer Menu')
));
}
add_action('after_setup_theme', 'register_main_menu');
/*Custom menu class*/
function add_class_to_li($classes, $item){
$classes[] = "nav-item";
return $classes;
}
add_filter('nav_menu_css_class', 'add_class_to_li', 10, 4);
这不会在” li”中添加” nav-item”类。有什么我需要更新的吗?
#1
你的theme_location应该与在functions.php文件中拥有的theme_location完全一样。因此, 你的阅读器菜单将是:
/*Render menu*/
<div class="main-nav">
<?php wp_nav_menu(
array(
'theme_location' => 'Primary', //this will be Primary, not header-menu
'container' => 'ul', 'menu_class' => 'nav'
)
);
?>
</div>
评论前必须登录!
注册