Archived topic
How to hide no index post?
5 replies · Started by Akshay on August 9, 2022
Hi there,
adding a noindex tag won't remove a post from your site, its simply a meta tag that search engine bots will see.
If you want to exclude a post from your blog then add this snippet:
function exclude_single_posts_archive($query) {
if ( !is_admin() && !is_singular() && $query->is_main_query() ) {
$query->set('post__not_in', array(1223, 776,878) );
}
}
add_action('pre_get_posts', 'exclude_single_posts_archive');
In the array: array(1223, 776,878) is a list of Post IDs replace those with the one ( or many ) that you want to exclude.
Thanks David,
One more question. That particular post is still listed in the recent post and category widgets. Is there a way to hide them as well?
Hi Akshay,
As an alternative, you can use a Query Loop Block instead of these two blocks. In the Query Loop Block, you can exclude specific posts.
Reference: https://docs.generateblocks.com/article/query-loop-overview/
Thanks a lot Fernando!
You’re welcome Akshay!