How to add active class on current menu item page?

How to add active class on current menu item page?

Senior Developer Asked on January 23, 2017 in WORDPRESS.
Add Comment
1 Answer(s)

WordPress wp_nav_menu Code

 wp_nav_menu(array(‘theme_location’ =>’primary’,’menu_class’ => ‘navigation’)) 
“functions.php” is stored with each Theme in the Theme’s subdirectory in wp-content/themes. Each theme has its own functions file, but only the “functions.php” in the active Theme affects how your site publicly displays. If your theme already has a functions file, you can add code to it. If not, you can create a plain-text file named “functions.php” to add to your theme’s directory.
WordPress active page Code

 add_filter(‘nav_menu_css_class’, ‘add_active_class’, 10, 2 ); function add_active_class($classes, $item) { if( $item->menu_item_parent == 0 && in_array(‘current-menu-item’, $classes) ) { $classes[] = “active”; } return $classes; } 
Team Leader Answered on March 19, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.