我认为使用Custom Walker.
首先在主题的functions.php
class WP_Walker extends Walker_Nav_Menu
{
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\\t", $depth);
$output .= "\\n$indent<div id=\'mega\'><ul class=\'sub-menu\'>\\n";
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\\t", $depth);
$output .= "$indent</ul></div>\\n";
}
}
注册自定义导航后。主题中以下代码的用法:
wp_nav_menu(array (\'theme_location\' => \'your-theme-location\', \'walker\' => new WP_Walker));
使用
custom walker, 扩展start\\u lvl()和end\\u lvl方法。
custom walker