I have some problems with nav menu in Wordpress. I have a nav-menu
<nav id="nav-menu">
<ul>
</ul>
</nav>
now I want add a div before and after ul:
<nav id="nav-menu">
<div></div>
<ul>
</ul>
<div></div>
</nav>
I've tried several hours but can't found the solution. Can anyone help me with this, thank you. I don't want to just display <ul></ul> by wp_nav_menu() and put HTML code <nav> and <div> before wp_nav_menu().
I know this is 3 years old, but you can do exactly what you say, in wp_nav_menu set the items_wrap attribute:
wp_nav_menu(
array(
'theme_location' => 'menu',
'items_wrap' => '<div class="div-inserted-inside-wrapper-before-ul">New div inserted</div><ul id="%1$s" class="%2$s">%3$s</ul>'
)
);
So this extra has been included in items_wrap:
<div class="div-inserted-inside-wrapper-before-ul">New div inserted</div>
btw the default for items_wrap is:
wp_nav_menu(
array(
'theme_location' => 'menu',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'
)
);
That will end up with html output like this (a custom div inside wrapping div, before menu ul):
<div id="menu-wrapper" class="menu-wrapper">
<div class="div-inserted-inside-wrapper-before-ul">New div inserted</div>
<ul id="menu" class="menu">
<li class="menu-item">
<a title="Menu Item" href="#">Menu Item</a>
</li>
...
</ul>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With