Skip to content

Commit 0b9d068

Browse files
committed
added support for dropdown menu (responsive) alignment
1 parent da098a5 commit 0b9d068

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

functions.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,38 @@
22
// bootstrap 5 wp_nav_menu walker
33
class bootstrap_5_wp_nav_menu_walker extends Walker_Nav_menu
44
{
5+
private $current_item;
6+
private $dropdown_menu_alignment_values = [
7+
'dropdown-menu-start',
8+
'dropdown-menu-end',
9+
'dropdown-menu-sm-start',
10+
'dropdown-menu-sm-end',
11+
'dropdown-menu-md-start',
12+
'dropdown-menu-md-end',
13+
'dropdown-menu-lg-start',
14+
'dropdown-menu-lg-end',
15+
'dropdown-menu-xl-start',
16+
'dropdown-menu-xl-end',
17+
'dropdown-menu-xxl-start',
18+
'dropdown-menu-xxl-end'
19+
];
20+
521
function start_lvl(&$output, $depth = 0, $args = array())
622
{
23+
$dropdown_menu_class[] = '';
24+
foreach($this->current_item->classes as $class) {
25+
if(in_array($class, $this->dropdown_menu_alignment_values)) {
26+
$dropdown_menu_class[] = $class;
27+
}
28+
}
729
$indent = str_repeat("\t", $depth);
830
$submenu = ($depth > 0) ? ' sub-menu' : '';
9-
$output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
31+
$output .= "\n$indent<ul class=\"dropdown-menu$submenu " . esc_attr(implode(" ",$dropdown_menu_class)) . " depth_$depth\">\n";
1032
}
1133

1234
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
1335
{
36+
$this->current_item = $item;
1437

1538
$indent = ($depth) ? str_repeat("\t", $depth) : '';
1639

0 commit comments

Comments
 (0)