Add this to your child theme’s functions.php:
add_filter('nav_menu_css_class', 'fix_category_menu_active_class', 10, 2); function fix_category_menu_active_class($classes, $item) { // If we're on a category archive if (is_category()) { // Get the ID of the blog page (posts page) $blog_page_id = get_option('page_for_posts'); // If this menu item is the blog page if ($item->object_id == $blog_page_id) { // Remove the active classes $classes = array_diff($classes, array( 'current-menu-item', 'current_page_item', 'current_page_parent', 'current-menu-ancestor' )); } } return $classes; }
How it works:
- It checks if you’re on a category archive.
- Then removes the current-menu-item class from the blog menu item if it’s being wrongly marked active.
Related Posts:
- Can’t extend some core classes
- How to let mobile navigation menu close when link is clicked?
- Override get_template_directory() in child theme?
- why is translation not working on theme?
- renaming an admin menu item with decimal array index number
- How can I hook into and edit the text of a wp_nav_menu tag?
- How do I remove a require_once admin panel from the parent theme from the child theme functions.php?
- is there a simple way to list every templates / php files used to generate a specific page?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- removing tags from wp_list_pages() using PHP
- Replacing the NavWalker dropdown element
- How to add specific menu on a specific page or pages
- WordPress menu deletes when trying to add a hook
- Overriding a theme redux file in child theme
- Second Navigation inside header
- selected menu item
- child theme inherticance and php autoload
- How do I target the child theme with get_bloginfo();?
- Deregister and Dequeue Stylesheets From a Plugin and Enqueue a Child’s Stylesheet/s
- Adding tawk.to code just before body tag on functions.php file
- How to display conditional-content if wp_nav_menu( $args ) retruns something
- Show comments menu in dashboard only if the site has comment
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- Count top level menu items
- create a select input with menus created on a custom options page
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- Menu — How to add “current-menu-grand-ancestor” css class
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Menu Limitations
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- two columns of posts on homepage, one of them “favorites”
- Custom Menus: dynamic highlighting problem with custom home link
- Custom Background by Page IDs
- Copyright info change – Corporate Plus Theme PHP [closed]
- Register a menu – Error Header
- How to style one item from main navigation?
- Automatically add images to a menu
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- WordPress filter load_textdomain_mofile not working inside a child theme’s functions.php but works form inside a plugin
- Use custom template on custom post type
- Add value to new attribute inside WordPress menu items
- Include style.css in the Child Theme with PHP
- Menu Items fail to save correctly, cause reset of related page metadata
- Dropdown menu for categories
- Menu Custom Data Attributes
- Get the name of menu item with wp_nav_menu
- Problems clearing cache
- How to modify mobile nav menu text in theme
- Output only links using wp_nav_menu()
- How to add aria role and schema markup to custom walker container
- Nav menu from plugin to theme
- Extend Menu Walker Output
- Where should I copy a PHP file from wp-includes to, in order to override it in my child theme?
- how to add a div inside wp_page_menu
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why in this WordPress theme I can’t see the Main Menu?
- Remove submenu item from list
- conditional: if is page, and all subpages
- wp nav menu: show submenu below li item
- Trying to change featured image from 180×180 to full width on home page
- Remove the Tag from wp_nav_menu
- Styling an “active” link outside of WordPress default menu
- Dynamic menu with custom post types
- How to edit background color of only one sidebar?
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu
- File from parent theme imported to child theme doesn’t work – any ideas?
- How to set Nav as a default menu in wordpress
- PHP “warning include_once(): Failed to open stream” Simple HTML DOM in WordPress Child Theme
- AJAX numerical pagination problem in TwentyFifteen-child theme
- How to locate parent theme functions and add functions to my wordpress child theme?
- Redirect User when they click Menu Option
- Modifying child theme’s header
- Get Child of Child Pages in custom Menu
- WordPress files break if I edit them, but adding a closing PHP tag fixes it
- Add the shortcodes from the enfold theme to the other theme
- How to disable sub menu items from being created?
- Difference between “Walker_Nav_menu” and “walker”
- Local WordPress from Git repo, where to set document root?
- Vertical Menu for one page only
- PHP drop down menu for my get_category child of
- Pulling a variable into the wp_nav_menu function
- Beyond widget side menu editing, with the php page, custom template
- Editing existing pre-created menus in PHP
- wp nav menu without label
- Active class not working on custom menu link using add_menu_page
- Sidebar current menu item for parent
- Remove all nav menu classes except those which begin with certain letters
- How to add a code for lastpostdate after/inside a specific menu link?
- Add the “.current-menu-item” class to tag?
- WordPress adding in site URL to header links
- Can’t remove menu items added by plugin
- Adding a unique class to wp_nav_menu
- Open WordPress Page from selected option dropdown
- Remove Unused Menu Locations
- Show a text in menu
- make my custom theme support polylang plugin
- Can’t make an external api call in php side of wordpress child theme
- Unable to remove action from parent theme via child theme
- How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?