Hide posts from WP home page

Hiding posts from showing up on the home page is something I have been thinking about all week. Last night I finally dug into the WP Codex and figured out how to make it happen. Hide WordPress posts from appearing on your home page by adding their post IDs to the following array (where you see 603 and 621), and place this code before the loop starts in your theme’s main index file.


<?php
if( is_home()){ query_posts(array('post__not_in' => array(603,621))); }
?>

This code prevents posts from showing up on your home page, but allows them to be directly accessed and shown in views other than the home page like category archive. The posts will also be included in your RSS feed.

F.A.Q.

  • Where do I put this code?

    Place the code before the loop starts in your theme’s index. To edit the index file, browse to Design > Theme Editor > Main Index Template. Place the code anywhere before this line: <?php if (have_posts()) ?>

  • How do I find the IDs of my posts?

    Go to Manage > Posts and mouseover the titles of your posts. Look at the URL showing up in your browser’s status bar. The post ID will be at the end of the edit post link URL you see.

Most ‘hidden post’ tutorials explain to use a hidden category. The problem with the category approach is the need to hide the category from showing up in the sidebar and any other place it may appear. WP does not have built in hidden or secret categories. The idea of chasing out a category everywhere categories are shown on my WP is not an attractive idea.

This code lets me publish posts that are not intended for prime time viewing but work great as a post rather than a page.

21 comments

  1. Corey, this is what I requested when I had DR revamped. All industry announcements are in the Industry Announcement category but do not display on the home page. I use this category for Press Releases only. I wanted to have include these press releases on DR for several reasons (that seem to be paying off).

    However, I did keep the Industry Announcements in the main RSS feed and I’m thinking about changing this and having them in a separate feed. This industry doesn’t have too many people subscribing to my RSS feed (a little over 600 maybe) but I have had a few comments mentioned that “DR had turned into a PR source”, because they only read the RSS feeds and not visit the site.

    Any suggestions on breaking up the RSS feed?

  2. esan, I am using this code on almost all of my WP sites now, so I am confident that it does work. I am glad you found a solution to your particular problem.

  3. I want to show only my latest post on my homepage, but for some reason, it shows all of my posts.

    When I click on the post’s ‘links’ in my menu, each post shows individually, which is the way they should.

    I’m using WP and have set my posts number to “1” in my Reading settings, but it has no effect.

  4. Jim:

    If you change the setting and it has no effect on your site, you may be using a theme that has hard-coded changes that bypass the settings. If you change your site to a different theme temporarily, does it work?

  5. No it doesn’t. I’ve activated the WP Default theme and a couple of others and the homepage still shows all the posts.

  6. Many thanks Corey, it works :)

    the only question I have:
    how do you specify which post you’d like to show up on Home Page?

    I’ve changed array(603,621) to array(1) and it shows my latest post, my aim is to make it show only my first post on home page

    Thanks a lot for your help

    Regards,
    Artur

  7. Artur:

     

    Using array( 1 ) simply excludes your oldest post from showing on the home page. Your latest post would have the highest number. This code example demonstrates how to hide posts from the home page. To change the number of posts that are shown on the home page, there is an option in Settings >> Reading to change the number of posts per page. You could change this setting to 1 to accomplish what I perceive to be your goal.

  8. Hello,

    This is exactly what I need for a project I am working on, but can’t seem to get it to work.

    I think it is with the array #’s, but don’t know for sure.

    Can you please advise?

    Thank you,
    Regards,
    Bert

  9. Thank you for sharing this, i found this really handy for tucking away a holiday post that was looking out of place.

  10. Corey, great post, it was exactly what I was looking for. It excludes the posts great.

    I have found one bug and I’m not sure if I’m the only one. After inserting the code if you click on “older posts” at the very bottom of the index page, instead of showing older posts it just shows my index page again but the url says that it is on page two.

    Let me know if you have any suggestions, other than that it worked well.

  11. Hello Corey,
    I really found this blog helpful. But i want to remove every post from home page. I mean, in future if anyone add a post from admin then it will automatically viewed in home page. Now the it will be annoying if i had to put an id every time whenever i create a post right.. So isn’t there any idea if i can hide post from home page.

Leave a comment

Your email address will not be published. Required fields are marked *