Update: The question was actually how to wrap the submenus, not the whole menu. Here are 2 options:
using jQuery:
<script type="text/javascript">
// run this before the script that sets up the dropdowns:
jQuery(document.ready(function($){
$('.sub-menu').wrap('<div class="dropdown"></div>');
})
</script>
using PHP 5.3+ (slightly more complex option, but thought i’d post it):
<?php
$dom = DOMDocument::loadHTML(wp_nav_menu(array(
'menu' => 'main', // change this to your theme location
'echo' => false,
)));
// Find all uls
$uls = $dom->getElementsByTagName('ul');
// Find & wrap each sub menu
foreach ($uls AS $ul)
{
if ($ul->getAttribute('class') == 'sub-menu')
{
// create the dropdown wrapper div
$wrapper = $dom->createElement('div');
$wrapper->setAttribute('class', 'dropdown');
// Replace ul with this wrapper div
$ul->parentNode->replaceChild($wrapper, $ul);
// Append this ul to wrapper div
$wrapper->appendChild($ul);
}
}
echo $dom->saveHTML($dom->getElementsByTagName('div')->item(0));
?>
// OLD ANSWER:
Check out the container_class
option of wp_nav_menu()
: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Your menu’s ul
will automatically be wrapped in a div; you can set the class of the div using that option:
<?php
wp_nav_menu(array(
'theme_location' => 'my_location', // change this to your theme location
'container_class' => 'dropdown',
));
?>