Replace news
with your custom post type and menu-item-000
with the menu item you want to highlight.
function wpdev_nav_classes($classes) {
// Remove "current_page_parent" class
$classes = array_diff( $classes, array( 'current_page_parent' ) );
// If this is the "news" custom post type, highlight the correct menu item
if ( in_array('menu-item-000', $classes) && get_post_type() === 'news' ) {
$classes[] = 'current_page_parent';
}
return $classes;
}
add_filter('nav_menu_css_class', 'wpdev_nav_classes');
If you have more than one post type, it would be better to use a switch statement. Let me know if that’s the case, and I’ll update the code.
Related Posts:
- Navigation won’t update to show full path to single post
- Remove current_page_parent nav class from blog index when in CPT
- Extend walker class with custom post types [closed]
- How to Programically add to the new WordPress menus
- Highlight nav menu terms
- Custom Taxonomy Breadcrumb Navigation
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- Adding Custom Taxonomy Archive Link to Nav Menu Shows Up As (Invalid)
- Why are navigation items saved in the database?
- adding .current* tags to custom post types and taxonomies
- Menu Multiple Taxonomies
- Set menu active state for custom posttype and category, given custom taxonomy term
- Correct classes for WordPress menu items
- Custom Taxonomy Navigation, with current menu items for children?
- Second Set of Eyes: One custom taxonomy shows in Appearance > Menus, one does not
- Hide post navigation if current post is in a category with only one post
- Use custom walker to add taxonomy terms to main nav menu
- Losing Nav Active State in Menu
- Custom Post Types in the WordPress Navigation Menu
- Which Template Page Should I Use?
- How can i automatically add CPT single pages as sub menu items
- 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
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- How to create a Child & Siblings menu for a custom post type?
- Automatically add CPT UI categories to the menu
- Custom post type category link + add to menu
- Navigation not working for custom post type pages
- wp_nav_menu doesn’t seem to work on custom post type pages
- Custom nav menu current item custom link problem
- Calling the first & last post by category in custom post type
- List all posts from custom post type by taxonomy
- Custom Taxonomy Showing in WP Menu
- Plugins for putting Custom Post Types into the Menu
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- current_page_item and custom post type?
- 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
- Custom Taxonomy back-end customizations
- Showing up my custom post type in primary navigation
- Show a Category X’s custom post type on Category X archive page?
- Paging doesn’t work?
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- Get Taxonomy Term Title by it’s URL
- Add custom taxonomy to post content body?
- custom taxonamy and post type
- Taxonomy custom post type URL
- Display as tree terms of taxonomy and custom posts for each term of taxonomy
- Custom post type url with category
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- How do I move/order posts with a tag to the end?
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Add custom image size for custom post type or taxonomy
- Get taxonomy values based on wp_query results
- Display post as term id
- Ajax Custom Post Filter is not filtering
- Need Output Custom Taxonomy from Custom Post Type
- Display all taxonomy terms, add class if term applies to current post
- WordPress sort search results by custom order
- How to filter wp_list_categories output with some custom post type meta query?
- Custom Post Type – No Results Found
- Return the latest post from a custom Taxonomy and Post Type
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Don’t know how to show custom taxonomies from a custom post_type
- How to Filter custom post type by taxonomy?
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Custom taxonomy rewrite give pagination 404
- How to duplicate entire custom post type
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Use Custom Post Type archive page for the taxonomies term archive page
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Is it possible to have dedicated page for parent/child taxonomy?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Can a Custom Taxonomy be named “category” like normal Posts?
- How to use terms from the same custom taxonomy in different roles in a custom post type?
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- How do I display the taxonomy term alongside the post type post title?
- Display custom post type category, while in a CPT category, then the posts beneath
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- Hide parent categories when clicked, and show it’s childs
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Get related posts of child term of custom post type
- Limit amount of posts made within a custom taxonomy
- custom-taxonomy/post_name instead of the default post_type/post_name
- Filter term taxonomy metabox in custom post type
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- Group CPT posts by custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Filter CPT posts by one or more categories
- Custom taxonomy and custom post type – wrong permalinks and template
- Setting up taxonomy to relate various custom post types – advice on structuring?
- Getting categories of posts under a custom taxonomy
- Post count by month of taxonmy term
- How can I make the slug of the taxonomy also the slug of the custom post
- Query taxonomy of taxonomy of custom post type