nav_menu_css_class filter-hookWP 3.0.0

Filters the CSS classes applied to a menu item's list item element.

Usage

add_filter( 'nav_menu_css_class', 'wp_kama_nav_menu_css_class_filter', 10, 4 );

/**
 * Function for `nav_menu_css_class` filter-hook.
 * 
 * @param string[] $classes   Array of the CSS classes that are applied to the menu item's `<li>` element.
 * @param WP_Post  $menu_item The current menu item object.
 * @param stdClass $args      An object of wp_nav_menu() arguments.
 * @param int      $depth     Depth of menu item. Used for padding.
 *
 * @return string[]
 */
function wp_kama_nav_menu_css_class_filter( $classes, $menu_item, $args, $depth ){

	// filter...
	return $classes;
}
$classes(string[])
Array of the CSS classes that are applied to the menu item's <li> element.
$menu_item(WP_Post)
The current menu item object.
$args(stdClass)
An object of wp_nav_menu() arguments.
$depth(int)
Depth of menu item. Used for padding.

Changelog

Since 3.0.0 Introduced.
Since 4.1.0 The $depth parameter was added.

Where the hook is called

Walker_Nav_Menu::start_el()
nav_menu_css_class
wp-includes/class-walker-nav-menu.php 176
$class_names = implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $menu_item, $args, $depth ) );

Where the hook is used in WordPress

wp-includes/default-filters.php 648
add_filter( 'nav_menu_css_class', 'wp_nav_menu_remove_menu_item_has_children_class', 10, 4 );