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:

YouTube Preview Image

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 and creator of the WP RSS Aggregator plugin. He loves blogging and is the founder of WP Mayor. Jean also blogs about internet marketing at Fit for Blogging.

9 Responses

  1. sjmsing
    sjmsing January 14, 2014 at 17:09 | | Reply

    Thanks, code worked for me.

  2. adamjameswoods
    adamjameswoods February 10, 2014 at 09:26 | | Reply

    Hi, Can this piece of code be implemented with just the basic WordPress.com CSS upgrade?

    Being a novice, I’m not sure if this article is about .org sites or .com sites.

    Thanks

    Adam

  3. Krystle S
    Krystle S March 6, 2014 at 11:47 | | Reply

    I have the same question as adamjameswoods — does this work (and if so where do I put in it) for a basic wordpress.com site with the Custom Design Upgrade.

  4. 8ivek
    8ivek April 27, 2014 at 00:52 | | Reply

    Thank you very very much the code worked for me as well :)

  5. Bingbaling
    Bingbaling May 28, 2014 at 12:44 | | Reply

    My website goes blank after I paste the code in the functions.php file. Not cool x)

  6. nev
    nev September 9, 2014 at 10:29 | | Reply

    Does excluding a category automatically exclude its sub/child-categories?

  7. nev
    nev September 9, 2014 at 10:57 | | Reply

    There are errors in the code above, but I can’t write the corrections here because the page refuses to render them.

    All instances of ampersand followed by lowercase g followed by lowercase t followed by semi-colon should be replaced by a hyphen followed by a greater-than sign

  8. Nicki
    Nicki September 12, 2014 at 19:24 | | Reply

    Thanks so much for this!

Leave a Reply