How to Hide WordPress Categories

How to Hide WordPress Categories: In the following simple solution, I show you how to keep a selection of categories from displaying on your WordPress pages and posts. This can be useful if you no longer wish to use or display specific categories on your site, but have already been indexed for the category content from search engines such as Google and Bing. Upon completion of this tutorial, the permalink structure of the hidden categories are still made available to the search engines, however, the categories you have chosen to hide are no longer prominently displayed on your blog to the visitor.

How to Hide WordPress Categories

If you want to keep certain categories from showing on your WordPress site but still maintain their URLs for SEO purposes, there are multiple ways to hide them. You can use code snippets, CSS, or even plugins to achieve this. Below are the most effective methods.

Step 1: Find Your Category IDs

Before hiding categories, locate their IDs:

  1. Go to Posts > Categories in your WordPress dashboard.
  2. Hover over the category name and check the URL at the bottom of your browser for tag_ID=### (this is the category ID).

WordPress cat_ID

Step 2: Hide Categories in the Blog Loop

To exclude categories from the main blog page or archive pages:

function exclude_categories_from_blog($query) {
    if ($query->is_home() && $query->is_main_query()) {
        $query->set('cat', '-1,-2'); // Replace -1,-2 with the category IDs to hide
    }
}
add_action('pre_get_posts', 'exclude_categories_from_blog');

Step 3: Hide Categories in Widgets

Exclude categories from the default WordPress category widget:

function exclude_widget_categories($args) {
    $args['exclude'] = '1,2'; // Replace 1,2 with category IDs to hide
    return $args;
}
add_filter('widget_categories_args', 'exclude_widget_categories');

Step 4: Hide Categories from RSS Feeds

function exclude_categories_from_feed($query) {
    if ($query->is_feed) {
        $query->set('cat', '-1,-2'); // Replace -1,-2 with category IDs
    }
}
add_action('pre_get_posts', 'exclude_categories_from_feed');

Step 5: Hide Categories in Category Lists

function wpb_exclude_category($wp_list_categories) {
    $exclude = array(1,2); // Replace 1,2 with IDs
    foreach ($exclude as $cat_id) {
        $wp_list_categories = str_replace("cat-item-$cat_id", "hidden-cat", $wp_list_categories);
    }
    return $wp_list_categories;
}
add_filter('wp_list_categories', 'wpb_exclude_category');

Step 6: Hide Categories with CSS

Sometimes a simple CSS solution is enough, e.g., to hide categories in a widget or menu:

.cat-item-1, .cat-item-2 {
    display: none !important;
}

Step 7: Hide Categories from the Sidebar Using a Plugin

If you prefer not to touch code, you can use a PHP-enabled widget:

  1. Install and activate the PHP Code Widget Plugin.
  2. Go to Appearance > Widgets and drag a PHP Code widget to your sidebar.
  3. Add this code, replacing the numbers with your category IDs:
<ul>
<?php wp_list_categories('orderby=name&exclude=1,2,3&title_li='); ?>
</ul>
  1. Click Done and Save Changes
  2. Check your site — the selected categories should no longer display in the sidebar.

Final Notes

  • Backup your functions.php file before making any changes.
  • You can combine methods: use pre_get_posts for loops, widget filters for sidebar widgets, and CSS for additional styling control.
  • Hidden categories remain indexable by search engines unless you specifically set them to noindex.

By implementing these methods, you can control which categories appear on your site, keeping your content organized and your visitor experience clean.