By default the Roots Theme highlights custom post type archive menus as well as the “Blog” archive menu buttons. The solution is to remove/replace the “active” classes for those menu buttons, and re-add it to the proper post type’s menu button.
If you created and are using a custom post type in the roots theme, you may have come across a glitch where when you are active on your custom post types archive page (archive-customposttype.php) or single custom post page (single-customposttype.php) the default archive.php (ie. Blog) menu item also may appear highlighted in the main navigation menu (top header menu). This can be quite frustrating, here is a quick fix to add to your functions.php file to fix the menu highlighting problem.
Swap out the menu-item-xxx
for you menu item class.
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/** * Fix nav menu active classes for custom post types */ function roots_cpt_active_menu($menu) { if ('base_service' === get_post_type()) { $menu = str_replace('active', '', $menu); $menu = str_replace('menu-services', 'menu-services active', $menu); } if ('base_portfolio' === get_post_type()) { $menu = str_replace('active', '', $menu); $menu = str_replace('menu-portfolio', 'menu-portfolio active', $menu); } return $menu; } add_filter('nav_menu_css_class', 'roots_cpt_active_menu', 400); |