Wordpress: setting output wp_nav_menu, adding div to nested ul

I am creating a website that uses a mega-drop-down menu of styles, which is created using sections around the nested ul submenu.

Does anyone know how to customize the output of the menu generated by Wordpress (wp_nav_menu) to add containing divs around the nested sub menu ul?

There are two options.

'before' => '', 'after' => '',

but unfortunately, they only add content to the actual link, and not the entire submenu.

If you have any pointers or they did it before I will be very grateful.

Greetings

Dave

+3
source share
1

!

( functions.php ), , div div

class Walker_Page_Custom extends Walker_Nav_Menu {
/**
 * @see Walker::start_lvl()
 * @since 2.1.0
 *
 * @param string $output Passed by reference. Used to append additional content.
 * @param int $depth Depth of page. Used for padding.
 */
function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<div class='sub'><div class='sub-top'><!-- --></div><!--sub-left --><div class='sub-mid'><ul>\n";
}

/**
 * @see Walker::end_lvl()
 * @since 2.1.0
 *
 * @param string $output Passed by reference. Used to append additional content.
 * @param int $depth Depth of page. Used for padding.
 */
function end_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "$indent</ul><span class='clear'><!-- --></span></div><!--sub-mid --><div class='sub-bottom'><!-- --></div><!--sub-bottom --><span class='clear'><!-- --></span></div><!--sub -->\n";
}

}

wp_nav_menu,

 'walker' => new Walker_Page_Custom

, -!

Dave

+11

Source: https://habr.com/ru/post/1764469/


All Articles