admin管理员组文章数量:1130349
I am trying to invert the order of <li> and <a> in a wp_nav_menu, since for a responsive mobile design I like more when the click is done in all the <li> and not only in the word / s of the link <a> because is easier for the finger.
Thank you.
PS: I must say that I am a newbie in Wordpress development.
This is the code I use:
<div id="header-menu-nav">
<nav>
<?php
wp_nav_menu(array(
'container'=> false,
'items_wrap' => '<ul>%3$s</ul>',
'theme_location' => 'menu'
));
?>
</nav>
</div>
And the answer I get is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">
<a href="index.php">Home</a>
</li>
</ul>
</nav>
</div>
What I want is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<a href="index.php">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">Home</li>
</a>
</ul>
</nav>
</div>
I am trying to invert the order of <li> and <a> in a wp_nav_menu, since for a responsive mobile design I like more when the click is done in all the <li> and not only in the word / s of the link <a> because is easier for the finger.
Thank you.
PS: I must say that I am a newbie in Wordpress development.
This is the code I use:
<div id="header-menu-nav">
<nav>
<?php
wp_nav_menu(array(
'container'=> false,
'items_wrap' => '<ul>%3$s</ul>',
'theme_location' => 'menu'
));
?>
</nav>
</div>
And the answer I get is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">
<a href="index.php">Home</a>
</li>
</ul>
</nav>
</div>
What I want is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<a href="index.php">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">Home</li>
</a>
</ul>
</nav>
</div>
Share
Improve this question
edited Dec 16, 2018 at 21:33
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Dec 16, 2018 at 21:30
user157104user157104
1
- Note that the desired HTML you've specified is invalid. I take it you're trying to make the entire menu item clickable, not just the text? If so then this is not the solution, and the solution can be found entirely via CSS. If you got WP to output this, browsers would try to correct the DOM and it would not be what you ended up with – Tom J Nowell ♦ Commented Dec 17, 2018 at 0:29
2 Answers
Reset to default 2<ul>
<a>
<li></li>
</a>
</ul>
Is not valid HTML. An <a> tag cannot be a child of a <ul> tag. So what you're asking for isn't possible. It's not your actual problem either.
Your problem is a styling problem. If you want a larger touch target on the link, you need to add padding around the <a> tag, not the <li> tag.
Finally I have kept the correct HTML format:
<ul>
<li>
<a></a>
</li>
</ul>
And in CSS I put the element <a> with display: bock; and the padding that I want, and therefore occupies 100% of the elementu <li>.
Thank you.
I am trying to invert the order of <li> and <a> in a wp_nav_menu, since for a responsive mobile design I like more when the click is done in all the <li> and not only in the word / s of the link <a> because is easier for the finger.
Thank you.
PS: I must say that I am a newbie in Wordpress development.
This is the code I use:
<div id="header-menu-nav">
<nav>
<?php
wp_nav_menu(array(
'container'=> false,
'items_wrap' => '<ul>%3$s</ul>',
'theme_location' => 'menu'
));
?>
</nav>
</div>
And the answer I get is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">
<a href="index.php">Home</a>
</li>
</ul>
</nav>
</div>
What I want is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<a href="index.php">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">Home</li>
</a>
</ul>
</nav>
</div>
I am trying to invert the order of <li> and <a> in a wp_nav_menu, since for a responsive mobile design I like more when the click is done in all the <li> and not only in the word / s of the link <a> because is easier for the finger.
Thank you.
PS: I must say that I am a newbie in Wordpress development.
This is the code I use:
<div id="header-menu-nav">
<nav>
<?php
wp_nav_menu(array(
'container'=> false,
'items_wrap' => '<ul>%3$s</ul>',
'theme_location' => 'menu'
));
?>
</nav>
</div>
And the answer I get is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">
<a href="index.php">Home</a>
</li>
</ul>
</nav>
</div>
What I want is:
<div id="header-menu-mobile-nav">
<nav>
<ul id="header-menu-mobile-nav-ul">
<a href="index.php">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-181">Home</li>
</a>
</ul>
</nav>
</div>
Share
Improve this question
edited Dec 16, 2018 at 21:33
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Dec 16, 2018 at 21:30
user157104user157104
1
- Note that the desired HTML you've specified is invalid. I take it you're trying to make the entire menu item clickable, not just the text? If so then this is not the solution, and the solution can be found entirely via CSS. If you got WP to output this, browsers would try to correct the DOM and it would not be what you ended up with – Tom J Nowell ♦ Commented Dec 17, 2018 at 0:29
2 Answers
Reset to default 2<ul>
<a>
<li></li>
</a>
</ul>
Is not valid HTML. An <a> tag cannot be a child of a <ul> tag. So what you're asking for isn't possible. It's not your actual problem either.
Your problem is a styling problem. If you want a larger touch target on the link, you need to add padding around the <a> tag, not the <li> tag.
Finally I have kept the correct HTML format:
<ul>
<li>
<a></a>
</li>
</ul>
And in CSS I put the element <a> with display: bock; and the padding that I want, and therefore occupies 100% of the elementu <li>.
Thank you.
本文标签: menusReverse the order of ltligt and ltagt in a wpnavmenu
版权声明:本文标题:menus - Reverse the order of <li> and <a> in a wp_nav_menu 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749091705a2314621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论