Force categories widget to show empty cats

This snippet uses a Filter to add default args to the wp_list_categories call that is made when the “Categories” widget is rendered on the front end.

It is particularly useful for forcing the display of Category link even if they have no posts in them, since that is not something you can just check/uncheck on the Widgets page. For the full list of default args for wp_list_categories , check out the WP Codex.

Code Snippet:

add_filter( 'widget_categories_args', 'mytheme_widget_cat_args' );
function mytheme_widget_cat_args($cat_args) {
    // the default for "hide_empty" = 1, so
    $cat_args&#91;'hide_empty'&#93; = 0;
    // we can override any other defaults here too
    return $cat_args;

Posted in Pure hacks