Home / category / Force categories widget to display empty categories
  • How to Force categories widget to display empty categories

    force-categories-widget-to-display-empty-categories

    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.

    wordpress snippet : PHP

    <>
    <?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;
    }
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    widget_categories, get_categories, widget_categories_args, add_filter, _e,
  • thanks for code

    • No problem glad to hear you like the snippet!

  • vikram

    thanks..nice code…

  • Rat Fink

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

  • James

    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.

  • 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.