How to Show / Hide Categories in WordPress (Ultimate Guide)

Categories are an essential tool for organizing content and improving navigation in WordPress. But you may not always want to display all of your categories, especially empty ones without any posts.

In this ultimate guide, you‘ll learn several methods to easily show and hide categories in WordPress.

Why Show or Hide Categories in WordPress?

Before jumping into the how-to, let‘s briefly go over some reasons why you might want to customize your category display:

  • Hide irrelevant or unused categories – Avoid clutter by hiding categories that don‘t have any posts yet.

  • Show empty categories – Make new or upcoming categories visible so users can start filing content.

  • Improve site architecture – Only display categories relevant to each section.

  • Optimize for search engines – Prevent thin content issues by hiding empty category archives.

According to Moz, thin content pages with little unique text can dilute your site‘s indexing and ranking abilities. Hiding empty categories prevents those types of issues.

Now let‘s look at a few different methods to show and hide categories.

Method 1: Display All Categories (including Empty Ones)

By default, WordPress will automatically hide categories that don‘t have any posts. Here‘s how to override that and display all categories:

  1. Open your active theme‘s functions.php file. If you‘re not sure where this is, try looking in /wp-content/themes/your-theme/.

  2. Add the following code:

// Function to alter category arguments
function display_all_categories( $args ) {

  // Show empty categories
  $args[‘hide_empty‘] = 0;  

  return $args;

}

// Hook our function to the get_terms_args filter
add_filter( ‘get_terms_args‘, ‘display_all_categories‘ ); 
  1. Save your changes. Now WordPress will show all categories, even if they don‘t have any posts.

You can display these categories normally using wp_list_categories(), category widgets, etc.

This approach works well if you want to show all categories site-wide. But what if you only want to conditionally show some categories?

Method 2: Conditionally Show or Hide Specific Categories

For more granular control, you can use the ‘category__in‘ or ‘category__not_in‘ arguments to selectively show or hide categories.

For example, to only show categories 1 and 2:

$args = array(
  ‘category__in‘ => array(1, 2)  
);

$categories = get_categories( $args );

Alternatively, you can hide a specific category like this:

$args = array(
  ‘category__not_in‘ => array(3) 
);

$categories = get_categories( $args );

Here are two more examples with sample category IDs:

// Only show categories 15 and 27
$args = array(
  ‘category__in‘ => array(15, 27)
);

// Hide category 10
$args = array(
  ‘category__not_in‘ => array(10)  
);

To find the ID of a category, check the URL when editing that category. The ID will be the number after tag_ID= or category_ID=.

This gives you precise control to tailor category visibility for different areas.

Method 3: Prevent Search Engine Indexing for Hidden Categories

When hiding empty categories, you may also want to prevent search engines from indexing those category pages with thin content.

The easiest way is to use an SEO plugin like Yoast SEO or All in One SEO.

For example, with Yoast SEO:

  1. Go to Categories and find the edit screen for the category you want to hide.
  2. Expand the Yoast SEO section.
  3. Under Robots Meta, check the "noindex" box.
  4. Update the category.

This will tell search engines not to index this category page.

For All in One SEO, navigate to the category editor and go to the Advanced tab. From there you can set the Robots Meta value to ‘noindex, follow‘ or ‘noindex, nofollow‘.

Recap and Benefits

To summarize, here are three easy ways to show and hide categories in WordPress:

  • Method 1: Display all categories by filtering get_terms_args
  • Method 2: Conditionally show/hide specific categories
  • Method 3: Prevent indexing of hidden categories

Customizing your category visibility provides the following benefits:

  • Avoid clutter from empty or irrelevant categories
  • Improve site architecture and navigation
  • Optimize SEO by hiding thin content
  • Showcase new or upcoming categories
  • Better organize user-submitted content

As you can see, it just takes a few lines of code to gain complete control over category display in WordPress.

I hope this guide helps you clean up your content architecture. Let me know if you have any other WordPress questions!

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.