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>
<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.