How to Hide a Post from the Homepage in WordPress
Last Updated: August 10, 2020 in Guides
You might have plenty of reasons to hide your posts from the homepage – hiding a post that covers sensitive topics, questioning the writing quality of an article, or simply avoiding showing it on your homepage because it doesn’t make the first impression you want to make.
Most WordPress themes will show the latest posts first by default, but thankfully, there are several approaches that can help you to hide your posts. From simple manual coding to helpful plugins.
Make sure to keep on reading as I will be showing you five simple ways to hide your posts from the homepage in WordPress.
Hide a Post Manually
To manually hide a post from the homepage, you must add custom code to the theme's functions.php
file.
To start, you'll need the post's ID number. Simply go to Posts -> All Posts and hover your mouse on top of the post you want to hide. The post's URL will show up at the bottom left of your screen. The ID number is located between post= and &action, as highlighted in the screenshot.
Once you get the ID number, what you'll need next is the code below.
function wpb_exclude_from_home($query) { if ($query->is_home() ) { $query->set('post__not_in', array(ID_here)); } } add_action('pre_get_posts', 'wpb_exclude_from_home');
Put the snippet at the end of your theme's functions.php
files and replace "ID_here" with your post's ID number.
To hide multiple posts, just add the ID numbers separated by a comma; e.g. (34, 35, 37).
Make the Post Private
If you want to avoid coding completely, make your posts private instead. It will be visible to admins only. You also can make private both your published and soon-to-be-published pieces.
It's pretty simple and easy to do. To hide a published article, go to the post and choose Edit. On the right side of the editor, you'll find Status & Visibility as seen below.
From there, you can hide the post by selecting Private.
The process is similar to the soon-to-be-published posts as well. Before publishing the article, simply set it to Private so that your visitors cannot see the pieces.
Using a Plugin
You also can use the WP Post Hide plugin. This tool has helped thousands of users to hide posts from their homepage easily.
Go to Plugins -> Add New menus, then search for "WordPress Hide Posts" to install. After the installation finished, this plugin will appear at the menu bar of your editor.
This plugin allows you to choose from which sections you want to hide the post – your front page, categories, search, tags page, or authors page, as seen below.
Keep in mind that this plugin won't disable the permalink – it's still accessible. Plus, the post's SEO ranking won't be affected either, because the pieces will stay on your sitemap. It will still appear if you search it on search engines.
Hide Posts from the Archive Page
Normally, the archive page shows all your posts to the visitors in reverse chronological order (unless you use a way to reorder posts manually). From this page, your visitors can easily search articles even from years ago only by clicking the desired year.
If you want to hide posts from the archive page, you'll need the post's ID number and some custom code. While the process is quite similar to the first method, the snippet is different.
Find the post ID by using the same method as before, next, you'll need to add the snippet below to your functions.php
file:
function exclude_single_posts_archive($query) { if ($query->is_archive() && $query->is_main_query()) { $query->set('post__not_in', array(ID_here)); } } add_action('pre_get_posts', 'exclude_single_posts_archive');
Make sure that you have replaced the "ID_here" section with your post's ID number before copying and pasting the snippet to the file.
Alternatively, you can use another plugin that could help you to hide one or multiple posts – Ultimate Category Excluder. This plugin allows you to hide the categories from the front page, feeds, archives, or search, as seen below.
Once the plugin is installed and activated, go to Settings -> Category Excluder, and from there, choose to hide your categories on provided selections.
By utilizing this tool, you can immediately hide your posts before or after publishing them by assigning it to the hidden category.
Conclusion
Hiding your posts from the homepage is possible with the help of these five simple methods.
Manually hide the posts from your homepage or the archive page by adding custom code to your theme’s functions.php
file. Or just set your post’s visibility to Private.
You also can utilize WordPress plugins, like WP Post Hide and Ultimate Category Excluder. To hide specific posts, WP Post Hide is your best choice. But for bulk exclusion, like categories, Ultimate Category Excluder works best.
There you go — five ways to hide your posts from the homepage. I hope you find them helpful.