• Resolved Danigar

    (@danigar)


    Hi there:

    In my main menu I have the category “Fruits”, which has the subcategories “Apples” “Grapes” and “Oranges”.

    When I go into the page “Fruits”, CMW’s menu appears showing:
    [ Fruits Apples Grapes Oranges ]

    I’d like that instead of “Fruits” it says “All”, ie:
    [ All Apples Grapes Oranges ]

    How can I change that? I guess I have to edit some $parent variable in the plugins source code, but I’m not sure.

    Thanks!

    https://wordpress.org/plugins/custom-menu-wizard/

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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;
    }

    Thread Starter Danigar

    (@danigar)

    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 ]

    Thread Starter Danigar

    (@danigar)

    Works like a charm. Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change parent's name’ is closed to new replies.