Family Encyclopedia >> Electronics

How to display empty categories in WordPress widgets

By default, the WordPress category widget does not display empty categories. Recently a new user asked us if it is possible to display empty categories in the WordPress widget to help him with his local development. In this article, we will show you how to display empty categories in WordPress widgets.

How to display empty categories in WordPress widgets

The first thing you need to do is add this simple code snippet to your child theme's functions.php file or a site-specific plugin.

 add_filter ('widget_categories_args', 'wpb_force_empty_cats'); función wpb_force_empty_cats ($ cat_args) $ cat_args ['hide_empty'] = 0; devuelve $ cat_args; 

This code hooks our custom function. wpb_force_empty_cats to widget_categories_args filter. Inside our function we have modified the option. hide_empty and make it false.

That's it, now you can drag and drop the categories widget to any sidebar or widget area on your WordPress site. The category widget will now display empty categories as well.

If you're working in a local development environment, we recommend that you add dummy content to your website for testing.

Also, don't forget to check out our guide on how categories and tags work in WordPress.

If you liked this article, please subscribe to our YouTube channel for more WordPress video tutorials. You can also find us on Twitter and Google.+.