Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

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

By default, WordPress does not show categories that are empty, meaning those without posts. However, there are times when you might want to display these categories, such as when you are planning to add posts soon or want to maintain your site’s visual consistency.

We have been creating content for WPBeginner since 2009, and we no longer have empty categories. But we understand that customizing how categories are displayed can improve user experience and the way your readers interact with your content.

In this article, we will show you some easy ways to hide or display a category in WordPress, depending on whether it has any posts.

Show or hide empty categories in WordPress

Why Hide or Display Empty Categories in WordPress

WordPress comes with two default taxonomies: categories and tags. While tags are used for specific topics of an article, categories are used in a much broader sense.

Many site owners use categories to create different sections for their WordPress websites.

For instance, at WPBeginner, we have different categories that cover the main sections of our overall content.

WPBeginner categories

By default, WordPress does not show empty categories in category widgets and category lists.

However, some website owners may still need to show empty categories on their WordPress blogs.

Category with no posts

For instance, if they are working on a custom theme design or if they simply want their users to see the empty categories and fill them with user-generated content.

Similarly, some websites may want to hide certain categories that don’t have any posts while still showing other empty categories.

In this guide, we will show you how to easily hide or display empty categories in WordPress.

How to Show Empty Categories in WordPress

WordPress now uses widget blocks to replace the old classic widgets. This makes it a bit more difficult to change the parameters used by the categories block to list categories.

To achieve our desired result, we will need to write our own code to list categories and then display it using a shortcode.

For this tutorial, you will need to add some code to your WordPress website. If you haven’t done this before, then see our guide on how to add custom code snippets in WordPress.

First, you need to add the following code to your WordPress theme’s functions.php file or add the code snippet using WPCode (recommended).

For detailed instructions, see our guide on how to easily add custom code in WordPress.

function wpb_list_categories() { 

// define category list parameneters
$args = array (
'echo'			=> false,
'title_li'		=> '',
'hide_empty'	=> 0
); 

// get categories list
$display_cats = wp_list_categories($args); 

//display custom categories list
return $display_cats;
}

// create shortcode
add_shortcode('custom_categories_list','wpb_list_categories');

This code simply uses our own parameters to list categories, and one of these parameters is to change the hide_empty category parameter.

After that, you can display your custom categories by adding the shortcode block to your sidebar or other widget area and then adding the [custom_categories_list] shortcode inside it.

Using shortcode to display custom list of categories

Once you are finished, don’t forget to update your widgets settings.

Then, you can visit your website to see the categories in action.

Displaying empty category

Hide Specific Categories in Your Category List

Similarly, you can use the same approach to exclude categories that you don’t want to be included in the categories list.

Simply modify the above code like this:

function wpb_list_categories() { 

// define category list parameneters
$args = array (
'echo'			=> false,
'title_li'		=> '',
'exclude'               => '12,16,21',
'hide_empty'	=> 0
); 

// get categories list
$display_cats = wp_list_categories($args); 

//display custom categories list
return $display_cats;
}

// create shortcode
add_shortcode('custom_categories_list','wpb_list_categories'); 

In this code, we have hidden the categories by adding the exclude parameter. Next to it, you need to provide the IDs of the categories you want to hide.

Tip: We have written a guide that shows you how to find category IDs in WordPress.

You can now go ahead and display your custom categories by adding the shortcode block to your widget area and then adding the [custom_categories_list] shortcode inside it.

Exclude Category Pages From Search Engines

If you are displaying empty categories on your website, then you may want to exclude them from search engines until you have some content there.

Some users may also want to exclude some categories from search engines to avoid duplicate content and other SEO issues.

To do that, you will need to install and activate the All in One SEO for WordPress plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

All in One SEO

All in One SEO for WordPress is the best WordPress SEO plugin on the market and allows you to easily control your site’s appearance in search results.

Once you have installed the plugin, you will see a setup wizard. It is quite self-explanatory, but if you need help, then follow our guide on setting up All in One SEO.

Next, you need to visit the Posts » Categories page on your WordPress dashboard and click on the ‘Edit’ link below the category that you want to exclude.

Edit category

On the Edit Category page, you need to scroll down to the All in One SEO section.

Then, switch to the ‘Advanced’ tab.

block search engines from indexing a category page in WordPress

From here, you need to turn off the ‘Default Settings’ option next to the Robots Setting. You will now see options to tell search engines not to follow and index this category.

Once finished, don’t forget to click on the ‘Update’ button to save your settings.

All in One SEO will now start telling search engines not to index or follow that particular page.

Note: WordPress posts filed under that category may still get indexed by search engines and will appear in search results.

Expert Guides on WordPress Categories

We hope this article helped you learn how to hide or display empty categories in WordPress. You may also want to see some other WordPress tutorials related to categories:

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

12 CommentsLeave a Reply

  1. Mr Cowan

    “By default, WordPress does not show categories that are empty.”

    Thank you so much for that. You have no idea how much hassle and time this issue has caused me. Nobody else ever mentioned it, that I read. My web host could not resolve the issue, but it’s so amazingly simple.

    Once again: thanks a million.

    • WPBeginner Support

      You’re welcome! It’s always the little things that make troubleshooting a problem difficult :)

      Admin

  2. MIke Dutton

    I wonder if it possible to adapt this for Taxonomy terms. So only display something if a particular Taxonomy term has posts.

  3. randy

    OMG so helpful for running and if statement to see if there are posts in a category, regular post type or custom post type. Many thanks!

  4. John Hartley

    Easiest example I found anywhere…saved me some heartache, so thanks!

  5. michelle

    really useful, thanks. I have placed a link back to this on my own blog so that I can share it with others :)

  6. Luke Jones

    Excuse me if I’m wrong but doesn’t it do this already in the most recent versions?

    • Editorial Staff

      Read the first two lines of the post. We already mention that using the wp-list-cats, yes it does, but if you are doing some more customization and need it hard coded without calling a function, then this is the way you will go.

      Admin

  7. Enk.

    It seems interesting but I seriously didn’t understand it. When we can name/rename a category from news to Blog. Whats the thing else than showing only if it has posts? *confused :s

    • Editorial Staff

      This is only for very customized settings, but it is still good to know for those who does not. Yes you can rename a category, but how many times. If you have 7 custom page templates where you want to call one category 7 different names, then how would you go about it. For Sales / Splash pages, this will help.

      Admin

      • Enk.

        ah thanks, now I can say its pretty useful. Thanks a ton ! :)

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.