Hide posts in the “uncategorized” category

These are two snippets that accomplish mostly the same thing.

The first snippet hides the display of content if it’s post is assigned to the Uncategorized category.

The second snippet hides the display of content if it’s post is assigned to the default WP category, even if it has been renamed.

These are useful in different cases. In the first, if a user eventually renamed “Uncategorized” to something more useful, then it would be displayed.

Code Snippet:

<?php
	// Hide the display of something if it has the category named "Uncategorized"
	if( !in_category( 'Uncategorized' ) ) {
        	// do something like:
        	the_category( ', ' );
        }

	// Hide the display of something if it uses the default category, initially named "Uncategorized"
	if( !in_category( 1 ) ) {
        	// do something like:
        	the_category( ', ' );
        }

?>

Posted in Posts, Conditional