Plugin Author
wizzud
(@wizzud)
CMW only provides the means to filter the menu items, not to edit them.
Assuming that you can’t modify the menu itself (because “Fruits” is probably only a small part of it), the code below will replace every occurrence of the string “Fruits” with “All”. But be warned : it’s an all-encompassing solution for any CMW-produced menu … and that may not be what you want!
add_filter( 'wp_nav_menu', 'my_cmw_nav_menu_as_dropdown', 10, 2 );
function my_cmw_nav_menu_as_dropdown( $nav_menu, $args ){
if( !empty( $args->_custom_menu_wizard ){
$nav_menu = str_replace( 'Fruits, 'All', $nav_menu );
}
return $nav_menu;
}
Thanks, that looks nice and -with some basic debugging- it works! 🙂
Anyhow, as usual the main menu has more categories than just “Fruits” (there’s also “Vegetables”, “Nuts”, and many other mock names 😉 Although we can add them manually to this code, a solution that replaces any parent Category name with the text ‘All’ would be the best.
Plugin Author
wizzud
(@wizzud)
add_filter( 'custom_menu_wizard_walker_items', 'my_cmw_items_filter', 10, 2 );
function my_cmw_items_filter( $elements, $args ){
if( !empty( $elements ) ){
$elements[1]->title = 'All';
}
return $elements;
}
$elements is the CMW-filtered set of menu items about to be passed through to WordPress’s walker.
$args is all wp_nav_menu’s arguments, plus CMW’s own (from the widget).
[ you can test for other conditions, such as class “cmw-level-1” being set, if you wish ]
Works like a charm. Thanks a lot!