[wp-trac] [WordPress Trac] #28620: When $depth argument is used in wp_nav_menu last level menu items still have .menu-item-has-children class, even though they are not shown

WordPress Trac noreply at wordpress.org
Tue Jun 24 13:37:41 UTC 2014


#28620: When $depth argument is used in wp_nav_menu last level menu items still
have .menu-item-has-children class, even though they are not shown
---------------------------+------------------------------
 Reporter:  slobodanmanic  |       Owner:
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Menus          |     Version:  3.7
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:  ui
---------------------------+------------------------------

Comment (by kucrut):

 Here's one approach:

 {{{
 public function start_el( &$output, $item, $depth = 0, $args = array(),
 $id = 0 ) {
         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

         $classes = empty( $item->classes ) ? array() : (array)
 $item->classes;
         $classes[] = 'menu-item-' . $item->ID;

         if ( ( -1 === $args->depth ) || ( $args->depth > 0 && ( ( $depth +
 1 ) === $args->depth ) ) ) {
                 $_classes = array_fill_keys( $classes, '' );
                 unset( $_classes['menu-item-has-children'] );
                 $classes = array_keys( $_classes );
         }

         // ...
 }}}

 If only {{{nav_menu_css_class}}} is passing the current {{{$depth}}} then
 all this could be done with a simple filter callback.

 I'll be happy to format this as a patch if it's considered the right
 approach.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28620#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list