X

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( ', ' );
        }

?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!