WordPress.org

Make WordPress Core

Ticket #36163: 36163.diff

File 36163.diff, 1.1 KB (added by csloisel, 4 years ago)

Adding submenu css class filter in start_lvl()

  • src/wp-includes/class-walker-nav-menu.php

    diff --git a/src/wp-includes/class-walker-nav-menu.php b/src/wp-includes/class-walker-nav-menu.php
    index 4c1a1f2..c1ff73d 100644
    a b public function start_lvl( &$output, $depth = 0, $args = array() ) { 
    5757                        $t = "\t";
    5858                        $n = "\n";
    5959                }
    60                 $indent = str_repeat( $t, $depth );
    61                 $output .= "{$n}{$indent}<ul class=\"sub-menu\">{$n}";
     60                $indent  = str_repeat( $t, $depth );
     61                $classes = array( 'sub-menu' );
     62
     63                /**
     64                 * Filters the CSS class(es) applied to a submenu container element.
     65                 *
     66                 * @since 4.8.0
     67                 *
     68                 * @param array    $classes The CSS classes that are applied to the submenu item's `<ul>` element.
     69                 * @param stdClass $args    An object of wp_nav_menu() arguments.
     70                 * @param int      $depth   Depth of menu item. Used for padding.
     71                 */
     72                $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', array_filter( $classes ), $args, $depth ) );
     73                $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
     74
     75                $output .= "{$n}{$indent}<ul" . $class_names . ">{$n}";
    6276        }
    6377
    6478        /**