I'm looking for a way to wrap a menu's top-level link and sub-menus into a custom div. I found this code that almost does the trick:
class Sub_Wrapper extends Walker_Nav_Menu {
function start_lvl(&$output, $depth = 0, $args = array()) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<div class=\"sub-menu-wrapper\"><ul class=\"sub-menu\">\n";
}
function end_lvl(&$output, $depth = 0, $args = array()) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul></div>\n";
}
}
This outputs the following:
<ul>
<li>
<a href="#"></a>
<div class="sub-menu-wrapper">
<ul class="sub-menu"></ul>
</div>
</li>
</ul>
Though I'd need the 'a href..' to be inside the wrapper as well, like this:
<ul>
<li>
<div class="sub-menu-wrapper">
<a href="#"></a>
<ul class="sub-menu"></ul>
</div>
</li>
</ul>
Any suggestions? Trying to do it via the walker class and avoid jQuery's .wrap().