如何使用WP_NAV_MENU在WordPress中显示自定义链接?
我正在创建一个一页自定义主题。我正在努力使用自定义菜单,因为我想显示自定义链接。
我已经在function.php文件中注册了菜单
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
,然后我在header.php文件中显示了这样的菜单:
<?php wp_nav_menu( array(
'theme_location' => 'top-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>
我已经为ul标记添加了自定义类,这还可以。导航有效,但仅适用于页面。当我创建一个页面时,该页面的链接显示在导航中。但是,创建自定义链接后,它们不会出现在导航中。
我正在搜索Stachoverflow,以搜索一些安静的时间,但没有成功。如何解决描述的问题?你有主意吗?
谢谢你的宝贵时间。
I'm creating an one-page custom theme. I'm struggling with a custom menu, because I want to display custom links.
I've registered menu in functions.php file
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
Then, I've displayed in header.php file like this:
<?php wp_nav_menu( array(
'theme_location' => 'top-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>
I've added custom classes for ul tag, and that is okay. Navigation works but just for pages. When I create a page, a link for that page shows up in navigation. However, after creating custom links they don't appear in navigation.
I'm searching the Stachoverflow for some quiet time, but without success. How to resolve a described issue? Do you have an idea?
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的注册标题菜单带有标头键,并试图通过Top-Menu的钥匙将其获取,这是不可能的。您必须使用标头键键添加并获取标头菜单。我们已经更新了代码。您可以使用此代码。
You have register header menu with header-menu key and trying to get it by key of top-menu which is not possible. You have to use the header-menu key to add and get a header menu. we have updated the code. you can use this code.