This repository was archived by the owner on Feb 10, 2020. It is now read-only.
This repository was archived by the owner on Feb 10, 2020. It is now read-only.
Open
Description
In case anyone wants it, I have managed to modify this nav-walker to support Multi-level submenus.
The submenus are written to fit to this submenu support css/script module: bootstrapthemesco/bootstrap-4-multi-dropdown-navbar.
The steps to support it are just changing a couple lines within the wp-bootstrap-navwalker.php
file.
- Add these const's to the class
class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {
public const BS_MAX_DEPTH = 2;
public const BS_DROPDOWN_MANUAL_DEPTH = 1;
- Replace
start_lvl
with this
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
if ($depth >= WP_Bootstrap_Navwalker::BS_DROPDOWN_MANUAL_DEPTH) {
$output .= $n . str_repeat( $t, $depth ) . '<ul class="dropdown-menu" role="menu">' . $n;
}
else {
$this->dropdown = true;
$output .= $n . str_repeat( $t, $depth ) . '<div class="dropdown-menu" role="menu">' . $n;
}
}
- Replace
end_lvl
with this
public function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
if ($depth >= WP_Bootstrap_Navwalker::BS_DROPDOWN_MANUAL_DEPTH) {
$output .= $n . str_repeat( $t, $depth ) . '</ul>' . $n;
}
else {
$this->dropdown = false;
$output .= $n . str_repeat( $t, $depth ) . '</div>' . $n;
}
}