Site logo

Archived topic

How to hide no index post?

5 replies · Started by Akshay on August 9, 2022

Viewing posts 1–6 of 6

Hi

Recently I added a noindex tag on a blog post. But that post is still appearing on the blog page and recent post widget. Is it possible to stop that post from appearing?

Noindex post: Link

Blog page: link

Thanks

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?

Thanks a lot Fernando!

You’re welcome Akshay!

This archived topic is closed to new replies.