Do you want to display all categories with your categories widget even if they’re empty? By default, the WordPress categories widget doesn’t show empty categories. Add this snippet to the functions.php of your WordPress theme to display all categories with the default categories widget even if they’re empty.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
<?php add_filter( 'widget_categories_args', 'force_widget_cat_args' ); function force_widget_cat_args($cat_args) { $cat_args['hide_empty'] = 0; return $cat_args; } ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).
Thank you, thank you! I was about to modify the WordPress options / widgets file, but this is much neater. Probably saved me a ton of future time, too.
thanks for code! i used it
Its doesn’t work 🙁
Hi james, I just tested this in the most recent version of wordpress and works perfectly. Remember what this does exactly is display categories even if they are empty. However it does this for the sidebar widget, so if things are not working properly I would make sure you have the snippet placed within the functions.php correctly. Assuming this has been done you may have a plugin or other code within functions.php that is stopping this from working.
I just tested this within the Twenty Eleven 1.1, that comes with wordpress.
Perfect — been looking for hours for this fix — glad I found you. Thanks so much!
No problem anytime.
thanks..nice code…
no problem anytime!
thanks for code
No problem glad to hear you like the snippet!