How to add active class in WordPress bootstrap menu using hook

PHP , , , , 0 Comments

Warning: Trying to access array offset on value of type null in /home/codenski/public_html/wp-content/themes/simple-east/content.php on line 37

When we implemented the bootstrap menu in WordPress. you may be frustrated with the built-in menu options. There isn’t an easy way to tell WordPress to swap out the current menu item class with bootstrap’s active class. there is given below hook. this following script write a script in the fucntion.php file

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

function special_nav_class ($classes, $item) {
if (in_array('current-menu-item', $classes) ){
$classes[] = ‘active ‘;
}
return $classes;
}

Warning: Trying to access array offset on value of type null in /home/codenski/public_html/wp-content/themes/simple-east/content.php on line 74

Leave a Reply

Your email address will not be published.