How To Hide Old Posts Without Deleting Them

You may occasionally want to curate the content that appears at the forefront of your blog. You may want it to be visible to search engines or via clicking on categories or tags, but not on your homepage.

Unfortunately, there are not a lot of good methods in WordPress of hiding certain posts without making them entirely private. I tried several WordPress hide plugins (like WP Hide Post) that appear to be abandoned and broke my page or didn’t work at all.

I finally settled on a solution that works well enough for my purposes. It requires the creation of an “Archived” category (you can call this whatever you want) and either a bit of custom code or some plugins. The post may still show up in things like “recent posts”, its tags will still show up in the tag cloud and it will be visible in any categories it is listed under. But importantly it will NOT be visible on your posts page. It is also important to note, the “Archived” category will show up in your list of categories. If this is something that is unfavorable to you, you could potentially use a plugin to exclude certain categories from the categories list.

To start, you will need to create your Archived category. You can call it whatever you want.

Now, you can use a plugin like Ultimate Category Excluder to choose what to exclude this category from. If this is the option you choose, you’re done!

A slightly more difficult option (but less dependent on plugins) is to just include some of your own code in the ‘functions.php’ file. I would not recommend doing this unless you are familiar with coding and feel comfortable editing your theme’s underlying files. If you are comfortable doing this, then I would at least recommend that you back up your site prior to messing around with your theme files directly. With all of that said, this is a relatively safe addition to your theme’s functions.php file if you are familiar with coding wp sites.

To make this change, you first need to determine your new category’s ID. Click on “Posts” inside your wp-admin page. Then click “Categories”. Click on the link to go to your newly created category and take a look at the URL. As of the time of this writing, you can ascertain the ID of the category (called the tag_id) from the url:

In my case, it is 54. Then head on over to Appearance > Theme Editor. You will see a menu for “Theme Files” (on the right in my case). Here you will find all of the files for your theme. Navigate to your functions.php file (called Theme Functions in my case) and click on it. Then you will want to add the following to the end of this file:

function exclude_category($query) { if ( $query->is_home() ) { $query->set( 'cat', '-ARCHIVE_CATEGORY_ID' ); } return $query; } add_filter( 'pre_get_posts', 'exclude_category' );
Code language: PHP (php)

Make sure to replace “ARCHIVE_CATEGORY_ID” with the ID you found earlier. It is important to leave the preceding dash (-) however.

Now, voila! Check your posts page and any posts that you have put into that category should be excluded from your posts page.

How To Hide Old Posts Without Deleting Them

Leave a Reply

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