You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simply updating the walker may not be enough to get menus working right, you may need to add wrappers or additional classes, you can do that via the above function as well.
138
138
139
+
### Usage with Bootstrap 5
140
+
141
+
Bootstrap 5 uses namespaced data attributes. All `data` attributes now include `bs` as an infix. The new attributes work just like the old ones. Here’s the menu toggle button from the example above with the renamed data attributes.
The walker also adds a data attribute for dropdown toggles via the `start_el()` method. Paste this to your functions.php to make the walker use the infixed data attibute.
* Use namespaced data attribute for Bootstrap's dropdown toggles.
155
+
*
156
+
* @param array $atts HTML attributes applied to the item's `<a>` element.
157
+
* @param WP_Post $item The current menu item.
158
+
* @param stdClass $args An object of wp_nav_menu() arguments.
159
+
* @return array
160
+
*/
161
+
function prefix_bs5_dropdown_data_attribute( $atts, $item, $args ) {
162
+
if ( is_a( $args->walker, 'WP_Bootstrap_Navwalker' ) ) {
163
+
if ( array_key_exists( 'data-toggle', $atts ) ) {
164
+
unset( $atts['data-toggle'] );
165
+
$atts['data-bs-toggle'] = 'dropdown';
166
+
}
167
+
}
168
+
return $atts;
169
+
}
170
+
```
171
+
139
172
### Menu Caching
140
173
141
174
On some sites generating a large menu that rarely ever changes on every page request is an overhead that you may want to avoid. In those cases I can suggest you look at storing menu results in a transient.
0 commit comments