By default the WordPress category widget does not show empty categories. Recently a new user asked us if it was possible to display empty categories in WordPress widget to help with hisΒ local development. In this article, we will show you how to display empty categories in WordPress widgets.
First thing you need to do is add this simple code snippet in yourΒ child themeβsΒ functions.phpΒ file or aΒ site specific plugin.
function wpb_force_empty_cats($cat_args) {
Β Β Β Β $cat_args[‘hide_empty’] = 0;
Β Β Β Β return $cat_args;
}
This code hooks up our custom function wpb_force_empty_catsΒ to widget_categories_args filter. Inside our function we have modified the option hide_emptyΒ and set it to false.
Thatβs all, you can now drag and drop categories widget to any sidebar or widget ready area on your WordPress site. The category widget will now display empty categories as well.
If youβre working on a local development environment, then we recommend that you add someΒ dummy contentΒ to your website for testing purposes.
Also donβt forget to check out our guide on howΒ categories and tagsΒ work in WordPress.
If you liked this article, then subscribe to ourΒ YouTube ChannelΒ for more WordPress video tutorials. You can also find us onΒ TwitterΒ andΒ Google+.