admin管理员组文章数量:1278880
While trying to add menu list as the following
<li>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<?php
wp_nav_menu(array(
'theme_location' => 'header_menu_location',
'echo' => false,
'items_wrap' => '%3$s'
));
?>
</div>
This function should show a list of items within div element but what I get is that list is being shown right after the outer li element. What's even weird about it is that when I do not use attribute 'items_wrap' the output is showing properly inside of the div container, only when I add to the args array the output list appears outside of its div container. What am I doing wrong?
While trying to add menu list as the following
<li>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<?php
wp_nav_menu(array(
'theme_location' => 'header_menu_location',
'echo' => false,
'items_wrap' => '%3$s'
));
?>
</div>
This function should show a list of items within div element but what I get is that list is being shown right after the outer li element. What's even weird about it is that when I do not use attribute 'items_wrap' the output is showing properly inside of the div container, only when I add to the args array the output list appears outside of its div container. What am I doing wrong?
Share
Improve this question
edited Sep 25, 2021 at 13:40
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Sep 25, 2021 at 13:27
user212871user212871
111 bronze badge
1 Answer
Reset to default 1It's not working for two reasons.
- You have
echo
set to false. This means it won't output anything unless youecho
it manually. - The resulting HTML structure is invalid.
You have items_wrap
set it %3$s
. This means that the individual menu items, which are <li>
tags, will be output without a wrapper. That would make the final structure this:
<ul>
<li>
<div class="dropdown-menu">
<li></li>
<li></li>
<li></li>
</div>
</li>
</ul>
That's not valid HTML. The <li>
tags need to be in an <ol>
or <ul>
, not a <div>
. The simplest solution is to change the div to a <ul>
:
<li>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<?php
wp_nav_menu(array(
'theme_location' => 'header_menu_location',
'echo' => false,
'items_wrap' => '%3$s'
));
?>
</ul>
本文标签: menuswpnavmenu() showing list in a different Position
版权声明:本文标题:menus - wp_nav_menu() showing list in a different Position? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741299523a2371011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论