wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Force categories widget to display empty categories

wordpress snippet

As you may already know the wordpress categories widget does not provide the option to display empty categories. Adding this snippet to the functions.php of your wordpress theme will force the categories widget to display empty categories.

snippet :  PHPcopy
add_filter( 'widget_categories_args', 'force_widget_cat_args' );
function force_widget_cat_args($cat_args) {
    $cat_args['hide_empty'] = 0;
    return $cat_args;
source →

Did you like this post? If so please share it with your friends. Thanks!

  • http://www.estetikfiyati.com Estetik fiyatlar?

    thanks for code

    • http://wpsnipp.com Kevin Chard

      No problem glad to hear you like the snippet!

  • vikram

    thanks..nice code…

    • http://wpsnipp.com Kevin Chard

      no problem anytime!

  • Rat Fink

    Perfect — been looking for hours for this fix — glad I found you. Thanks so much!

    • http://wpsnipp.com Kevin Chard

      No problem anytime.

  • James

    Its doesn’t work :(

    • http://wpsnipp.com Kevin Chard

       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.

  • onur

    thanks for code! i used it

  • MrBowJingles

    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.