WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/nav menu css class

Description

A filter hook called by the WordPress Walker_Nav_Menu class.

Usage

<?php function filter_handler$classes $item ){ ...... }

add_filter'nav_menu_css_class''filter_handler'10); ?>

Parameters

$classes
(array) (required) Nav menu item classes.
Default: None
$item
(object) (required) Nav menu item data object.
Default: None

Example

The following example adds a unique CSS class to a single, specific nav menu item.

function my_special_nav_class( $classes, $item ) {

    if ( is_single() && $item->title == 'Blog' ) {
        $classes[] = 'special-class';
    }

    return $classes;

}

add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );

Source Code

nav_menu_css_class() is located in wp-includes/nav-menu-template.php.

Changelog

Related

Navigation Menu: register_nav_menus(), register_nav_menu(), unregister_nav_menu(), has_nav_menu(), wp_nav_menu(), wp_get_nav_menu_items()

See Also

Plugin_API/Filter_Reference