Put this in your functions.php:
function additional_active_item_classes($classes = array(), $menu_item = false){
global $wp_query;
if(in_array('current-menu-item', $menu_item->classes)){
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'product' && is_post_type_archive('product') ) {
$classes[] = 'current-menu-item';
}
if ( $menu_item->post_name == 'product' && is_singular('product') ) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'additional_active_item_classes', 10, 2 );
This code check if you are on a page product archive or an single product and if so it adds the class current-menu-item
Related Posts:
- Adding a Custom Post Type into the menu screen
- Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Adding an Archive of Posts to the Navigation Menu in WordPress 3.0
- How to add custom post type archive page links to nav menu?
- Remove current_page_parent nav class from blog index when in CPT
- Creating “static” taxonomies to choose from, inside custom post type?
- Query menu_order custom post types
- Custom Post Type Menus
- How can I get my Custom Post Types to appear in nav-menus.php ‘Menu’?
- Highlighting current item of custom post types’ sub pages, listed by wp_list_pages
- Extend walker class with custom post types [closed]
- wp_list_pages not showing cpt as I expected
- automatically placing custom post types singles into submenu of main nav menu
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- How to Programically add to the new WordPress menus
- Which User Role for Custom Post Type Menu – wp_nav
- Editor access to menu: custom post type missing
- Settings page above CPT page in admin section
- Remove current_page_parent from posts page link in WordPress nav menu
- Highlight parent menu item when child post
- wordpress custom post type remove duplicate menu item
- Menu highlight custom post type archive
- adding .current* tags to custom post types and taxonomies
- How to get custom post type menu_name?
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- wp_nav_menu() mark current item ancestor of custom post type
- current-menu-item class for custom post type parent
- How to change the admin menu “Pages” to something else
- Menu Multiple Taxonomies
- how to get post slug from url in wordpress
- Navigation menus not showing because of custom post type filter
- Add/Remove current_page_parent class
- Set menu active state for custom posttype and category, given custom taxonomy term
- Update menu when saving settings
- Function to display custom post type on front page makes menu items dissapear
- custom post type not showing in menu
- Correct classes for WordPress menu items
- Custom Taxonomy Navigation, with current menu items for children?
- Customize the Dashboard Menu Editor
- Display posts from Custom Post Type in category page on front-end
- Use menus with anchors
- How to make this menu drop down or like accordion
- Custom Post Type Nav to Subpage
- Custom Post Types don’t highlight in menu nav
- Querying both pages and posts
- Using default WP menu functionality to link to custom post-type listing?
- How to display custom WP menus?
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- A page that shows a list of a specific custom post type
- Review site custom post type structure
- Custom Post Types in the WordPress Navigation Menu
- Ordering Submenu Pages in WP 3.1
- Including link to custom post type in ‘wp_list_pages’ function
- Which Template Page Should I Use?
- How can I use archive-{post_type}.php theme template?
- Custom Post Type Link added to menu won’t show in frontend
- How To Display A List Of CPT Posts In A Meta Box On Menus Page?
- Get custom post type categories to show up in menus
- How can I create an automatic drop down menu with my tags?
- WordPress menu with custom taxonomy
- Prevent custom post type from showing up in custom menus
- Custom Post Type – Portfolio no longer works
- highlight parent page menu item when in custom post type
- Custom post type post in custom menu
- Custom post type posts wont show in wp_nav_menu()
- Home page is getting current-menu-item even if it’s not home
- Placing Admin Post Metaboxes in Tabs
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- build child and anchestor three from post parent
- wordpress get menu id by custom post_type?
- wp_get_nav_menu_items doesn’t return custom post type item
- Automatically add CPT UI categories to the menu
- Possition a Custom Post Type Tab under Settings
- wp_nav_menu doesn’t seem to work on custom post type pages
- how to display notifications in the wordpress menu when a new post is published
- Menu disappears with custom post type link
- Use the page picker from wordpress menu creation page
- How to display custom post type in a submenu?
- current_menu_parent for custom post type and custom url
- Calling the first & last post by category in custom post type
- add current-menu-item to multiple custom post types
- Nav style for current page with custom post type
- Admin menu post type
- How to display the FAQ Archive page in my menu
- Custom Taxonomy Showing in WP Menu
- Plugins for putting Custom Post Types into the Menu
- No Current Class showing in Menu for Custom Post Types
- Custom post type in submenu with custom meta box as a title with custom html
- CPT Archive with parent page
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Setting a Master Menu on a Custom Post Type
- and custom post_types to custom menu
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Highlight specific menu item when custom post is page
- Navigation won’t update to show full path to single post
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Can’t add custom post type archive page to menu
- Trying to add CPT to menu automatically