I use this functions. First of all, you have to add some custom class to your menu item (allow class input in Screen options, it’s not visible by default).
function mark_menu_item_as_active($classes, $item) {
if( in_array('my-custom-class',$classes) && ( is_category('my-category') /* OR ...*/ ) ) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter('nav_menu_css_class', 'mark_menu_item_as_active', 10, 2);
This function iterates through all menu items, and you will find your target item with that custom menu class. Then you will check whatever conditions you have (is_category, …), and add another class to its classes (current-menu-item, …).
Related Posts:
- What Defines What Category A Post Picks (if in multiple)
- WordPress menu that shows all posts in a certain category like w3schools
- Exclude category from
- How to list recent posts in a wp nav menu?
- Disable sticky option for specific categories
- Redirect to another page using contact form 7? [closed]
- Is there a way to add the list of recent posts into the admin sub menu on hover?
- how to hide empty fields of post category description?
- Give posts a particular template based on the assigned category
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Programmatically add posts from specific category to menu
- wp_list_categories() Exclude All Categories Except One
- WordPress – When visiting a `single post/ single.php` my category menu item link becomes active
- I want to add the 10 most recent posts under a parent category on the main menu
- How to add class to specific navbar item when post parent category is in specific category
- Automatic Table of contents with categories and posts
- Change from all posts to specific categories post on main page?
- How to remove category and other tags from posts page
- Show category name in category.php when posts assigned to multiple categories
- Show posts assigned to multiple categories in current category page
- How to display related posts from same category?
- How to show related posts by category
- Display all posts from specific categories on a page
- How to disable Uncategorized category URL?
- Add role that restricts user to post in specific category
- Count posts in category including child categories
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Display all posts under child sub category in sidebar on post page?
- Authors in menu, template list post by author
- Count to how many categories a post belongs to
- How can I remove posts of a certain category from homepage after a specified time period?
- How To Remove Certain category Posts From the Blog Page
- Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
- Add icon/badge next to posttitle of specific category
- Admin Notices don’t display on the admin screen for certain post
- I am unable to publish/update post
- Saving category to a post, before publishing the post
- Stop users posting into category while still seeing contents of the category
- How to Restrict Previous & Next Post Link to Posts of Same Category?
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How to display two blog categories as separate sections on one page?
- How to create a template for Pages?
- How do I do a page break?
- why does wordpress ignore the post args?
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- get posts from Custom Post Type & Category
- Give Children Unique ID’s
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Sort by last word in title
- How to call posts under a specific category on static front page?
- Post-Archive like a page in a specific subdirectory
- How to display only one category in a custom post type?
- Get only X number of categories
- inserting a category into post
- Getting posts from some categories plus some individual posts
- Change layout of post depending on category
- latest post showing up twice on posts page
- Am getting duplicate data from get_posts()
- Different post views for different category views
- Possible?! A contextually titled back link
- Allow / show post comments in category pages
- How to select a category automatically based on a word in WordPress post title?
- Display default matabox of posts(add category) wordpress
- How display related post only in Default category on single
- How to get tags when using publish_post
- How do you change the permalink for posts for a single category?
- Posts are not displaying on their category and tag page
- how to create a category with wp_insert_post and post_category
- Exclude posts in a category on one page but show those posts on a different page
- How to add a block to a category page?
- Excluding category from post navigation in WordPress?
- Post Category link is same with Page link
- Show custom post category for single post
- Get a list of categories that are related to posts
- Querying posts from current category, using a variable as array argument
- Display post order ranking within wordpress loop
- Precedence of page permalinks over woocommerce product category links?
- Is there a global page/post/product/anything ID?
- Need help writing loop to display posts by categories in separate divs
- Add category selection to function request
- Page and Posts loading as index page? Not loading the content
- Query post category & remove any post id
- Multiple Post Repeat for Related Post Loop by Category
- Show Post number of specific Category
- WP Load post with ajax and apply isotope
- Display the current post author and his url in the post header
- how to show posts on different pages if number of post per page is one
- Is possible to create a custom link that creates a post that’s already categorized?
- Is it possible to have different header style blog titles in different categories?
- Category pages vs single post pages
- How to display subcategory articles in the category view?
- How do we display a certain category type on a page while hiding all others?
- Convert HTML5 to WordPress theme
- How to make posts appear under pages
- Add wrapper for a specific sub-menu
- Filters do not work when there are multiple (one works)
- WordPress Ajax load doesn’t work
- Error counting posts of category
- Display posts from a specific category on frontpage.php template?
- Cant display custom post type posts from a specific category WordPress