I’m having a problem with my custom theme not adding a custom class to my menu on the initial wp load (first page load).
I’m using the code mentioned above:
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;
}
Which works nearly perfectly. But when I visit my site it automatically goes to the “home” page by default, but because there appears to be no page_id or anything mentioned in the $_GET, no active css class is applied to any menu items. If I navigate the site from here via my menu, the active class is added normally.
How do I apply my active css class to the main page by default? Or to the default page that’s loaded if this can be specified?
Any feedback would be appreciated. Thanks.