Make WordPress Core

Changeset 40537


Ignore:
Timestamp:
04/23/2017 07:15:47 AM (8 years ago)
Author:
peterwilsoncc
Message:

Menus: Add filter to sub-menu class in nav menus.

Add new filter nav_menu_submenu_css_class to the Walker_Nav_Menu::start_el() method, allowing themers to modify the sub menu classes output by wp_nav_menu().

Props: csloisel, darthaud, raisonon.
Fixes: #36163.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-nav-menu.php

    r38575 r40537  
    5959        }
    6060        $indent = str_repeat( $t, $depth );
    61         $output .= "{$n}{$indent}<ul class=\"sub-menu\">{$n}";
     61
     62        /**
     63         * Filters the CSS class(es) applied to a menu list element.
     64         *
     65         * @since 4.8.0
     66         *
     67         * @param array    $classes The CSS classes that are applied to the menu `<ul>` element.
     68         * @param stdClass $args    An object of `wp_nav_menu()` arguments.
     69         * @param int      $depth   Depth of menu item. Used for padding.
     70         */
     71
     72        $classes = array( 'sub-menu' );
     73        $classes = apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth );
     74        $class_names = join( ' ', $classes );
     75
     76        $output .= "{$n}{$indent}<ul class='" . esc_attr( $class_names ) . "'>{$n}";
    6277    }
    6378
Note: See TracChangeset for help on using the changeset viewer.