Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Show Empty Categories in WordPress Widgets

Do you want to show empty categories in WordPress widgets?

By default, the Gutenberg block for categories and the site editor widget in WordPress don’t show categories that have no posts assigned to them.

In this article, we’ll show you how to easily show these empty categories in WordPress widgets or blocks.

Displaying empty categories in WordPress sidebar widgets and blocks

Why Show Empty Categories in WordPress?

By default, the WordPress categories widget or block doesn’t show empty categories.

Empty categories are categories that don’t currently have any posts assigned to them.

Empty categories with no posts

However, if you are in the middle of making a website, then you may need to show empty categories in sidebar widgets or elsewhere.

That being said, let’s take a look at how to easily display empty categories in your WordPress sidebar or block widgets. You can click the links below to jump to either method you prefer.

Method 1. Show Empty Categories in WordPress Widgets With WPCode

While you can add code snippets into your theme’s functions.php file, it’s best to use a plugin like WPCode.

The problem with adding custom code to your core WordPress files is that even the tiniest of mistakes can break your WordPress site, making it inaccessible.

We recommend using WPCode, the most popular code-snippet plugin out there. With it, you can easily and safely add any code you want to your WordPress site.

If you haven’t done this before, then check out our guide on how to add custom code snippets in WordPress.

First, you’ll need to install and activate the free WPCode plugin. For detailed instructions, see our guide on how to install a WordPress plugin.

Once activated, you’ll want to navigate to Code Snippets ≫ +Add Snippet.

WPCode add snippet

This brings you to the snippet library, which gives you dozens of proven short codes that work for a specific use case.

You’ll want to start by clicking on ‘Add Your Custom Code (New Snippet).’

Add your custom code

Make sure to add a title for the snippet such as ‘Empty Categories.’

Then, you can change the Code Type to ‘PHP Snippet’.

Php-snippet

Next, under the Code Preview box, add the following code:

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; 
}

It should look something like this:

Code preview

This code simply creates a custom categories list that includes empty categories as well as populated ones.

After that, you’ll need to toggle the switch from ‘Inactive’ to ‘Active’ in the top right corner.

Then, just click the ‘Save Snippet’ button.

Save snippet

Scroll down to the ‘Insertion box.’ Select the shortcode option next to ‘Insert Method.’

Since you want to add the categories to the main sidebar, you’ll need to copy the ‘Shortcode’ generated by WPCode.

Copy shortcode

Head over to Appearance ≫ Widgets in your WordPress admin area.

This page is where you can add code to the appearance of your website.

Appearance widgets

You’ll need to select the dropdown arrow for ‘Main Sidebar.’

Then click on the ‘+’ icon and choose ‘Shortcode.’

Add shortcode to main sidebar

Paste the shortcode generated by WPCode into the box.

This allows you to add your custom shortcode to the main sidebar.

Paste shortcode

Finally, click the Update button at the top right-hand corner of the page.

You can now go to your website to see your categories list in action.

Update main side bar

Now you can preview your website live.

It should display your empty categories as well as categories with posts.

Empty category displayed

You can also use this shortcode in your WordPress posts and pages.

This is a great way for visitors to browse by categories to find related topics.

Empty categories included in categories list

Method 2. Display Empty Categories in Classic Widgets

This method can be used if you have disabled block widgets and are using classic widgets on your WordPress website.

The advantage of this method is that instead of creating the shortcode, you can modify the behavior of the default category widget.

Simply add the following code to WPCode. You can follow the same steps from the example above.

add_filter( 'widget_categories_args', 'wpb_force_empty_cats' ); 
function wpb_force_empty_cats($cat_args) { 
$cat_args['hide_empty'] = 0; 
return $cat_args; 
} 

It should look like this:

Add shortcode to the classic editor

After that, you can simply add the widget to your sidebar. To do this, you can repeat the same process as Method 1 as well.

All you need to do is copy the shortcode generated by WPCode. Then paste it to the text widget and save your changes.

Finally, you can go check out your live website to see your changes.

You should now see empty categories displayed in the categories list.

Empty category displayed

We hope this article helped you learn how to easily display empty categories in WordPress widgets. You may also want to see these handy WordPress tips, tricks, and hacks or take a look at our WordPress theme development cheat sheet for more ideas.

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.

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

6 CommentsLeave a Reply

  1. Hello and thank you. I tried this and it worked but I found out I was searching for something little different. You know when you set it the way that only one line is shown – when I set it that ways it still doen not show the empty cats. You know what I mean? If yes can you help? :)

    Best wishes from Germany, Cologne

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.