How to Display Empty Categories in WordPress

We use Categories Widget to display a list of categories on your Website. However, by default, WordPress will display the categories which have posts. With the empty categories which don't have any posts, they will not show in the Categories Widget. So, what do you need to do if you want to add the empty categories to the Categories Widget? This article will show you how to do this now.

In this example, I've created categories on the WordPress Website:

  • Gallery (1) - the Gallery category has one posts
  • Uncategorized (13) - 13 posts
  • Video (0) -  0 posts
  • WordPress (0) - 0 posts
  • WordPress Plugin (3) - 3 posts
  • WordPress Theme (1) - 1 article

By default, when using the Categories Widget will only show the categories have more than one article as follows:

  • Gallery (1)
  • Uncategorized (13)
  • WordPress Plugin (3)
  • WordPress Theme (1)

And after I make changes, all categories will be shown, including the empty categories (Video (0), WordPress (0)). Now, we will go in detail how to do this.

First, you log into the WordPress admin page, select Appearance » Press Editor (Item 1). Next, you open the Theme Functions (functions.php file) (Item 2) and paste the code below into the file (Item 3):

/* Display empty categories
/* ------------------------------------ */
function display_empty_categories($cate) {

$cate['hide_empty'] = 0;

return $cate;
add_filter( 'widget_categories_args', 'display_empty_categories' );


Click on the Update File button to save the change.

Note: Before changing the functions.php file, you should backup the functions.php file. Thank you for reading!



You are here

Hải sản Vân Đồn

Choose a language