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

How to Show Empty Categories in WordPress Widgets

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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 will show you how to 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.

Seeing empty categories in widgets can prompt website owners to create content for those categories, filling gaps in their content strategy.

Beyond that, if you own a news site or blog post with guest posting capabilities, you might also want to show empty categories. That’s because it may encourage users to contribute content relevant to those categories. For instance, if users see an empty category related to a topic they are knowledgeable about, they might be more inclined to submit content for that category.

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 the 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, which is 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 shortcodes 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.’


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 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 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.

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

7 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Atilla Boz says

    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.