英文:
How to Change WordPress Menu Structure (ul > li to nav > a)
问题
我正在尝试创建WordPress菜单使用:
wp_nav_menu(
array(
'menu' => '顶部菜单',
'container' => 'nav',
'container_class' => '',
'theme_location' => '顶部菜单',
'items_wrap' => '<nav>%3$s</nav>'
)
);
问题是WordPress向导航中添加了ui > ul结构,而我想使用以下结构:
<nav>
<a href="page1.html">页面1</a>
<a href="page2.html">页面2</a>
<a href="page3.html">页面3</a>
<a href="page4.html">页面4</a>
</nav>
有没有想法如何实现这样的结构,以便我可以用无序/有序列表以外的任何内容来组织菜单?
英文:
I'm trying to create a WordPress menu using:
<?php
wp_nav_menu(
array(
'menu' => 'Top Mid',
'container' => 'nav',
'container_class' => '',
'theme_location' => 'Top Mid',
'items_wrap' => '<ul>%3$s</ul>'
)
);
?>
The problem is that WordPress adding a ui > ul structure to the navigation whereas I want to use the following structure:
<nav>
<a href="page1.html">Page 1</a>
<a href="page2.html">Page 2</a>
<a href="page3.html">Page 3</a>
<a href="page4.html">Page 4</a>
</nav>
Any thoughts on how this can be implemented so that I can structure the menu with anything else than the unordered/ordered list?
答案1
得分: 1
你可以使用此函数。这会添加<a>
标签。
$navItems = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
echo "<nav>";
echo strip_tags(wp_nav_menu($navItems), '<a>');
echo "</nav>";
英文:
You can use this function. This adds <a>
tag.
$navItems = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
echo "<nav>";
echo strip_tags(wp_nav_menu($navItems), '<a>');
echo "</nav>";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论