Skip to content

Commit 52350ae

Browse files
authored
Add info about missing edit shortcut fix to the readme
Closes wp-bootstrap#407
1 parent 4bdec67 commit 52350ae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ To set a disabled link simply add `disabled` to the **CSS Classes** field in the
204204

205205
Headers, dividers and text only items can be added within dropdowns by adding a Custom Link and adding either `dropdown-header`, `dropdown-divider` or `dropdown-item-text` into the **CSS Classes** input. _Note: This will remove the `href` on the item and change it to either a `<span>` for headers or a `<div>` for dividers._
206206

207+
### Missing Edit Shortcut in Customizer Preview
208+
209+
According to the documentation for [`wp_nav_menu()`](https://developer.wordpress.org/reference/functions/wp_nav_menu/) one has to provide an instance of the custom walker class in order to apply the custom walker to the menu. As the instance is not [JSON serializable](https://make.wordpress.org/core/2015/07/29/fast-previewing-changes-to-menus-in-the-customizer/) this will cause the menu edit shortcut to not appear in the Customizer preview. To fix this do the following:
210+
1. Provide the class name string instead of the class instance as value for the 'walker' key in the array of wp_nav_menu's arguments,
211+
```diff
212+
wp_nav_menu( array(
213+
'theme_location' => 'primary',
214+
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
215+
'container' => 'div',
216+
'container_class' => 'collapse navbar-collapse',
217+
'container_id' => 'bs-example-navbar-collapse-1',
218+
'menu_class' => 'navbar-nav mr-auto',
219+
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
220+
- 'walker' => new WP_Bootstrap_Navwalker(),
221+
+ 'walker' => 'WP_Bootstrap_Navwalker',
222+
) );
223+
```
224+
2. re-add the class instance by adding this filter to your `functions.php`
225+
```php
226+
function slug_provide_walker_instance( $args ) {
227+
if ( isset( $args['walker'] ) && is_string( $args['walker'] ) && class_exists( $args['walker'] ) ) {
228+
$args['walker'] = new $args['walker'];
229+
}
230+
return $args;
231+
}
232+
add_filter( 'wp_nav_menu_args', 'slug_provide_walker_instance', 1001 );
233+
```
234+
207235
## Changelog
208236

209237
Please see the [Changelog](https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/master/CHANGELOG.md).

0 commit comments

Comments
 (0)