Show empty categories in WordPress
I wanted to show all my categories on the screen on the sidebar widget, because if the category doesn’t have any posts inside the categories doesn’t show.
So, one way of fixing it is to assign an dummy post to all categories, and they will show then, but instead of doing that we can add a filter that will always show our categories, without assigning a post to all the categories in WordPress.
Open the file called “/wp-includes/default-filters.php” in the WordPress root directory, and add this snipped to the end of the file.
function force_widget_cat_args($cat_args) {
$cat_args['hide_empty'] = 0;
return $cat_args;
}
add_filter( 'widget_categories_args', 'force_widget_cat_args' );