How to Add Active Class to Current Menu Item in WordPress

By default, WordPress adds current-menu-item class to current navigation menu item. This is very useful for writing CSS code. However, sometimes you may want to add your own custom class to current menu item. You can easily perform this task by adding a small amount of code to your functions.php file located inside your theme directory.

add_filter('nav_menu_css_class' , 'ccw_add_active_class_to_nav_menu' , 10 , 2);
function ccw_add_active_class_to_nav_menu($classes, $item){
     if( in_array('current-menu-item', $classes) ){
             $classes[] = 'active ';
     return $classes;

Recommended : Integrating Facebook Login into Laravel Application


Leave a Comment.