admin管理员组文章数量:1122846
I'm working on a theme with custom menus, currently using WP 4.0.1.
I'm registering two menus in functions.php:
register_nav_menus(
array(
'primary' => __( 'Main Menu', 'wsy' ),
'secondary' => __( 'Secondary Menu', 'wsy' )
)
);
Then, displaying them in my header.php file:
<nav role="navigation">
<?php
wp_nav_menu(
array(
'theme_location' => 'primary',
'depth' => '1'
)
);
?>
</nav>
The problem is, when I select a specific menu from either the Menus page or the customizer, they stop showing up in my page. It doesn't matter which menu or which location, they just don't show up. When I reset the locations (choose "- Select -" from the dropdown) a default menu is shown.
WP_DEBUG is active, no errors. Tried it with WP 4.1, still nothing. Tried adding new menus, no luck. Tried with a single menu location and registering with register_nav_menu();
instead -- nothing works.
I even tried on a fresh WP install, no luck. Also tried without the depth parameter, nothing.
I'd appreciate any help with this. Thanks!
I'm working on a theme with custom menus, currently using WP 4.0.1.
I'm registering two menus in functions.php:
register_nav_menus(
array(
'primary' => __( 'Main Menu', 'wsy' ),
'secondary' => __( 'Secondary Menu', 'wsy' )
)
);
Then, displaying them in my header.php file:
<nav role="navigation">
<?php
wp_nav_menu(
array(
'theme_location' => 'primary',
'depth' => '1'
)
);
?>
</nav>
The problem is, when I select a specific menu from either the Menus page or the customizer, they stop showing up in my page. It doesn't matter which menu or which location, they just don't show up. When I reset the locations (choose "- Select -" from the dropdown) a default menu is shown.
WP_DEBUG is active, no errors. Tried it with WP 4.1, still nothing. Tried adding new menus, no luck. Tried with a single menu location and registering with register_nav_menu();
instead -- nothing works.
I even tried on a fresh WP install, no luck. Also tried without the depth parameter, nothing.
I'd appreciate any help with this. Thanks!
Share Improve this question asked Mar 25, 2015 at 5:30 WSYWSY 111 silver badge3 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 0You might need to use 'add_theme_support' for 'nav-menus' as well. See line 2 below:
if ( function_exists('wp_nav_menu') ) {
add_theme_support( 'nav-menus' );
register_nav_menus( array(
'primary' => __( 'Main Menu', 'wsy' ),
'secondary' => __( 'Secondary Menu', 'wsy' )
)
);
}
Then display your menu like so:
$nav_menu = 'primary';
if ( has_nav_menu( $nav_menu ) ) {
echo '<nav role="navigation">';
wp_nav_menu(
array(
'theme_location' => $nav_menu,
'depth' => 1
)
);
echo '</nav>';
}
本文标签: menuswpnavmenu() doesn39t work
版权声明:本文标题:menus - wp_nav_menu() doesn't work 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287617a1927920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP_Query
or the main query, or any function hooked topre_get_posts
or any instance ofquery_posts
. – Pieter Goosen Commented Mar 25, 2015 at 8:33