Family Encyclopedia >> Electronics

How to Display Empty Categories in WordPress Widgets: Proven Code Snippet

As experienced WordPress developers, we've helped countless users customize widgets for better site management. By default, the Categories widget hides empty categories, which can hinder local development or testing. Here's our reliable method to show them.

How to Display Empty Categories in WordPress Widgets: Proven Code Snippet

Add this proven code snippet to your child theme's functions.php file or a site-specific plugin:

add_filter( 'widget_categories_args', 'wpb_force_empty_cats' );
function wpb_force_empty_cats( $cat_args ) {
	$cat_args['hide_empty'] = 0;
	return $cat_args;
}

This hooks our custom function wpb_force_empty_cats into the widget_categories_args filter, setting hide_empty to 0 (false). Now, simply drag the Categories widget to any sidebar—it will display all categories, including empty ones.

For local development, we recommend adding dummy posts to simulate real content and test thoroughly.

Deepen your knowledge with our comprehensive guide on how categories and tags work in WordPress.

Liked this? Subscribe to our YouTube channel for more expert WordPress tutorials. Follow us on Twitter and Google+.