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:

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5, -34' );
return $query;

add_filter( 'pre_get_posts', 'exclude_category_home' );

If you’re not familiar with how to obtain the category 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 using a Plugin

If you’re absolutely not comfortable with editing your theme’s files, there is also a plugin alternative you can use.

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.

In case you’re looking for a powerful WordPress hosting and a knowledgeable support team that can help you easily with any hosting issue, check out SiteGround.

About Jean Galea

Jean Galea is a WordPress developer, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the podcast. His personal blog can be found at

Related Articles

  • Remove Category Base in WordPress

    Want to remove the useless /category/ from your WordPress categories permalinks? If yes, put this code in your functions.php and you're done!

  • A number of plugins are sprouting up, and their sole purpose is to hide the fact that you use WordPress. What's the reason for doing that? The number one reason…

  • logo woocommerce

    When WooCommerce displays the single product page, by default it shows the products categories. If you're not using categories to organize your products, it's usually a better idea to remove…

48 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 CSS upgrade?

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



    1. Silas Jura
      Silas Jura April 13, 2015 at 00:24 | | Reply

      No the code above would not work for because it is not CSS code. The code above is PHP code which is the programming language WordPress uses. CSS is (mostly) a styling language so very different from a programming language which gives WordPress it’s functions. Hope that helps for anyone seeing this in the future.

  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 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!

  9. TheNerdyNurse
    TheNerdyNurse November 18, 2014 at 22:20 | | Reply

    Does this still work if I assign multiple categories to a blog post?

  10. cmagnet
    cmagnet December 20, 2014 at 01:27 | | Reply

    Simply Exclude works great and it is very simple to use! Thank you for this article man!

  11. Adrián Rosales Conant
    Adrián Rosales Conant January 15, 2015 at 21:59 | | Reply

    Hi, thank you for sharing your teachings. I’m trying to hide posts from unsubscribe members along my site with out display restriction information or any register form. I’ve been searching a plugin but no success so far. Any idea? Thanks again! :)

  12. Jack K
    Jack K March 20, 2015 at 11:29 | | Reply

    Its very helpful, Thanks for sharing 🙂

  13. duongtrieu
    duongtrieu June 7, 2015 at 10:32 | | Reply

    It hides in homepage & post, page
    I want only homepage

  14. Personlig udvikling
    Personlig udvikling July 20, 2015 at 01:00 | | Reply

    Thanks! You just saved my day. I have been messing around with this problem for a while.

  15. Anna
    Anna August 6, 2015 at 21:26 | | Reply

    I messed up my ENTIRE blog today taking this advice. DO NOT copy and paste this code, and best practice is to just not touch PHP in general I’ve not learned. “Just insert the following code…” DONT!

  16. santoshsabbani
    santoshsabbani September 24, 2015 at 23:07 | | Reply

    Great! Thanks a lot!

  17. erpol53
    erpol53 October 9, 2015 at 01:55 | | Reply


    Great piece of code, thanks for it!

    I was wondering if this query could be changed to INCLUDE posts with a certain tag.
    Like, show on the homepage only the posts having the “home_page” tag, etc. ?



  18. veronika
    veronika November 5, 2015 at 16:15 | | Reply

    I’m sorry i don’t understand. i know what my ID is but what part is the ID in the code?

  19. Antonio
    Antonio January 2, 2016 at 10:37 | | Reply

    I have tried it and it doesn’t work.
    I have my post page in a different page not home page.
    I substituted home for page(IDcategory)

    it didn’t work, any suggestions?

  20. Gregory
    Gregory January 18, 2016 at 05:48 | | Reply

    This code works for me. Thanks for sharing!

  21. Mohammed
    Mohammed January 22, 2016 at 08:01 | | Reply

    Also excluding a category automatically exclude its subcategories?

  22. Colleen Ryer
    Colleen Ryer January 25, 2016 at 20:04 | | Reply

    HI, just wondering, I was able to exclude one category this way. But when I added a second, the new one shows on the home page ;(
    Is there anything else I could try?

  23. elsoar1
    elsoar1 March 3, 2016 at 16:10 | | Reply

    Really amazing, Thank you, Jean Galea
    it’s very easy to make on the wordpress blogs

  24. insign
    insign May 22, 2016 at 20:58 | | Reply

    Saved my day

  25. Mya
    Mya June 11, 2016 at 18:08 | | Reply

    sorry its not clear which row shall I insert the code.

    1. mark.zahra
      mark.zahra June 14, 2016 at 02:58 | | Reply

      Hey Mya, you simply need to add the code above to the end of your theme’s functions.php file.

  26. mukesh
    mukesh July 2, 2016 at 09:52 | | Reply

    Installed Ultimate Category Excluder, thank you for your post.

    i saw that others are able to post with their website but there is no option for me to write website link, why?? 😉

  27. Eddie Potros
    Eddie Potros September 28, 2016 at 14:55 | | Reply

    Tried this just now and works great. An explanation or breakdown of the code would help people understand it better though instead of just copying and pasting. Would make this post more valuable.

    1. Mark Zahra
      Mark Zahra September 30, 2016 at 03:15 | | Reply

      Glad you found it useful Eddie. What would you break down exactly? There isn’t much to the code, but if we can improve the explanation, we’re all ears 🙂

  28. K Yogesh Patel
    K Yogesh Patel September 28, 2016 at 23:43 | | Reply

    You explained about adding the code and it’s perfect but where exactly should I enter the code? Should it before <?php code or not.

    1. Mark Zahra
      Mark Zahra September 30, 2016 at 03:13 | | Reply

      Yogesh, no PHP code goes before at the end of your file, it should be above that.

  29. Munna Hossain
    Munna Hossain October 25, 2016 at 10:28 | | Reply

    Glad to have this article.It is really useful to me. I want to rename Uncategorized category in my WordPress site. Uncategorized category is really unprofessional and unskilful. That’s why I want to rename with another meaningful category. Can you tell me how to do it. Thanks for your article.

  30. Julio Maysonet
    Julio Maysonet November 21, 2016 at 18:51 | | Reply


    I see that big blogs hide their categories is there a reason for that?

  31. carter john
    carter john January 19, 2017 at 03:29 | | Reply

    Thanks for posting this interesting article.

  32. Akin
    Akin February 19, 2017 at 00:14 | | Reply

    Thanks for posting this article….It really helped to exclude a post from my homepage despite trying many options. Once again, thanks so much.

  33. Barra Prayoga
    Barra Prayoga February 21, 2017 at 01:45 | | Reply

    This code works for me. Thanks for sharing!

  34. Rahim
    Rahim June 13, 2017 at 22:12 | | Reply

    I was facing category option problem but after visit this site and read full article i have solved my old problem and thanks for sharing useful article.

  35. thuethamtuuytin
    thuethamtuuytin July 24, 2017 at 18:17 | | Reply

    I see that big blogs hide their categories is there a reason for that?

  36. Anjali
    Anjali September 15, 2017 at 03:51 | | Reply

    Thanks for the reply. I just looked where you suggested but still found no way to remove the category link, so I’ll go post where you suggested. Thanks again!

  37. Make your own silicone wristband
    Make your own silicone wristband February 13, 2018 at 07:37 | | Reply

    My brother recommended I would possibly like this blog.
    He wwas totally right. This postt actually made my day.
    You can not consider simply how a lot time I hhad spent for this information! Thank you!

  38. George
    George April 14, 2018 at 12:19 | | Reply

    The best way to hide categories is through the use of control panel of your theme. Otherwise you have to know how to modilfy a php page.

  39. dharmesh
    dharmesh April 19, 2018 at 21:29 | | Reply

    Thanks, good post

  40. Rohan
    Rohan October 8, 2018 at 06:14 | | Reply

    Thanks for sharing this wonderful WordPress Article. This code works for me.

  41. Frank
    Frank December 25, 2018 at 21:14 | | Reply

    i get an error when i do that and the plugin does not work for me since the script/theme has it’s own categories, so the plugin does not see them

    Warning: Cannot modify header information – headers already sent by (output started at /home/pacayo5/public_html/wp-content/themes/wpjobster-child/functions.php:1) in /home/pacayo5/public_html/wp-content/themes/wpjobster/includes/functions/functions-currency.php on line 12

  42. Alice
    Alice January 31, 2020 at 03:02 | | Reply

    Thanks for your useful guide. I can follow and hide categories from my homepage easily. Can you also recommend a solution to remove archives categories?

  43. Nhất Long
    Nhất Long March 6, 2020 at 20:51 | | Reply

    Great piece of code, thanks for it!

Leave a Reply