wp_nav_menu how to wrap whole sub-menu inside div

  php, wordpress, wp-nav-walker

I’m trying to add div to wrap all submenus inside. WordPress by default creates menu structure:

<ul id="menu-main" class="menu">
    <li>Parent
        <ul class="sub-menu">
            <li>Sub
                <ul class="sub-menu">
                    <li>Sub 1A</li>
                    <li>Sub 1B</li>
                </ul>
            </li>
            <li>Sub 2
                <ul class="sub-menu">
                    <li>Sub 2A</li>
                    <li>Sub 2B</li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

I would like to add div to wrap all submenu into one div (for mega menu purpose)
so it would look like:

<ul id="menu-main" class="menu">
    <li>Parent
        <div class="additional-div">
        <ul class="sub-menu">
            <li>Sub
                <ul class="sub-menu">
                    <li>Sub 1A</li>
                    <li>Sub 1B</li>
                </ul>
            </li>
            <li>Sub 2
                <ul class="sub-menu">
                    <li>Sub 2A</li>
                    <li>Sub 2B</li>
                </ul>
            </li>
        </ul>
    </div>
    </li>
</ul>

wordpress menu

Source: Ask PHP

LEAVE A COMMENT