How to Prevent Category Pages from Highlighting the Blog Menu in WordPress

When category archive pages automatically highlight your blog menu item in WordPress, it’s because WordPress typically
treats these as part of the blog hierarchy. Here are several methods to prevent this behavior:

Method 1: Use CSS to Remove Active State


.category .current-menu-item, 
.category .current_page_item {
    background: none !important;
    color: inherit !important;
    /* Add any other styles to reset the active state */
}

Method 2: Modify Menu Walker Class

Add this to your theme’s functions.php:


function adjust_category_menu_item_classes($items, $args) {
    if (is_category()) {
        foreach ($items as $item) {
            $item->classes = array_diff($item->classes, array('current-menu-item', 'current_page_item'));
        }
    }
    return $items;
}
add_filter('wp_nav_menu_objects', 'adjust_category_menu_item_classes', 10, 2);

Method 3: Use Conditional Menu Plugin

Install a plugin like “If Menu” to conditionally control menu items based on:

  • Page type (archive, category, etc.)
  • Specific categories
  • Other conditions

Method 4: Custom Nav Menu Walker

Create a custom walker class that checks is_category() and removes active classes accordingly.

Method 5: JavaScript Solution

jQuery(document).ready(function($) {
    if ($('body').hasClass('category')) {
        $('.current-menu-item, .current_page_item').removeClass('current-menu-item current_page_item');
    }
});

Choose the method that best fits your technical comfort level and theme structure. The CSS method is simplest but may
not work in all cases, while the PHP solutions are more robust.

Related Posts


WP Pagination Not Working for Custom Query: Troubleshooting Tips

Ever struggled with WordPress pagination code? Fret not! We’ve got your back. In this post, we...

How to Stop WordPress Plugin Shortcode from Duplicating on Reload

It can be frustrating when your WordPress shortcodes duplicate content on page reload. This usually ...

WordPress Force HTTPS Without Plugin: The Ultimate Method

Hey there! Are you running a WordPress website on WP Engine and want to make it more secure? Worried...

Data Validation Issues using `dangerouslySetInnerHTML` into Gutenberg Blocks

Using dangerouslySetInnerHTML in React, and by extension in Gutenberg blocks, is a powerful tool but...

Recent Posts