How to add css class to current menu item in WordPress ?

If you want to add css class to current menu item in WordPress.

add_filter('nav_menu_css_class' , 'rs_special_nav_class' , 10 , 2);
function rs_special_nav_class ($classes, $item) {
    if (in_array('current-menu-parent', $classes) ){
        $classes[] = 'active-item';
    }
    if (in_array('current-menu-item', $classes) ){
        $classes[] = 'active-item';
    }
    return $classes;
}
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *