How To Hide or Remove Categories from a WordPress Homepage

When displaying your latest posts on the homepage, you might want to exclude some categories from displaying on this page.

There are many reasons why you would want to do this. You might want to keep your homepage for only news posts and relegate the rest of the posts to other sections accessed through the menu.

In any case, what we will need to modify is the WordPress loop. All WordPress themes make use of the loop, and the best way to modify it is by using the pre_get_posts hook.

Removing categories from the homepage can sometimes turn out to be quite a frustrating act for beginners, so here’s the easy way to do it.

In your theme’s functions.php file, just insert the following code, replacing the category IDs with the ones you want to exclude:

If you’re not familiar with how to obtain the caetgory IDs, I recorded a short clip showing you how you can easily get the IDs for the categories you want to exclude:

Remove Categories from Homepage via Plugins

If you’re absolutely not comfortable with editing your theme’s files, there are also some plugin alternatives you can use.

Simply Exclude

simply exclude categories in wordpress

The Simply Exclude plugin works on the simple logic of the WordPress WP_Query object. This object is created and contains all the information needed to handle a page request from the user’s browser. So when the user points the browser to your site’s home page the WP_Query object is setup to query all the posts to display for your home page.

The Simply Exclude plugin adds a simply filter to this WP_Query object. Depending on the Simply Exclude settings for Home, Search, Archive, Feed and is Posts, Pages, Categories are being displayed.

Get Simply Exclude

Ultimate Category Excluder

ultimate category excluder

Ultimate Category Excluder is a WordPress plugin that allows you to quickly and easily exclude categories from your front page, archives, and feeds. Just select which categories you want to be excluded, and UCE does all the work for you!

Get Ultimate Category Excluder

From the two plugins, I prefer Ultimate Category Excluder, it’s a simpler plugin and works perfectly for most needs. Another advantage when using a plugin solution is that you can easily remove categories not only from the homepage but also from other sections of your site.

If you enjoyed this post, make sure to subscribe to WP Mayor’s RSS feed.

About Jean Galea

Jean Galea is a WordPress developer, podcaster and entrepreneur. He is the founder of WP Mayor and WP RSS Aggregator. His personal blog can be found at jeangalea.com. Check out his podcast focused on doing business with WordPress over at Mastermind.fm.

There are 29 comments

  
Please enter an e-mail address