7EC330B5-B132-499A-A307-65040D76AA48 How to display empty categories in WordPress

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 have posts. With the empty categories which don't have any posts, they will not be displayed 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 1 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 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!

 


Choose a language

You are here

SEARCH

CMMS Lazada

Subscribe YouTube

 

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

Chào mừng bạn đến với chuyên mục giới thiệu và cung cấp các mặt hàng hải sản của Vân Đồn. Hải sản Vân Đồn - Quảng Ninh | Tươi ngon, bổ dưỡng và đảm bảo với giá cả phải chăng. Xem trang....

UDEMY COURSES

Sitewide2of4-Oct-15dollars300x250