WordPress.org

Make WordPress Core

#24644 closed enhancement (duplicate)

Add "parent" class to menu items with sub-menus

Reported by: Looimaster Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: Cc:

Description

Currently there is no way to indicate that a menu has sub-menu (by inserting an arrow pointing downwards next to parent menu item) without custom menu walker or filters that will add 'parent' class to menu items that have sub-menus.

It would be great if that could become a default class in WordPress.

function add_parent_css( $classes, $item ) {
    global $dd_children;
    if( $dd_children ) {
        $classes[] = 'parent';
    }
    return $classes;
}
add_filter( 'nav_menu_css_class', 'add_parent_css', 10, 2 );

Change History (2)

comment:1 in reply to: ↑ description @Looimaster23 months ago

And here's the rest of the walker (can't update my original suggestion):

class custom_walker extends Walker_Nav_Menu {
  function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output){
    $GLOBALS['dd_children'] = (isset($children_elements[$element->ID]))? 1:0;
    parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
  }
  [...]
}

The reason I'm asking this is because plugins such as WPML add 'language switcher' as menu item and they ignore custom walker. Instead of chasing plugin authors and dropping them suggestions this could be a default feature of WordPress.

Last edited 23 months ago by Looimaster (previous) (diff)

comment:2 @SergeyBiryukov23 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.