0

Is there a way to avoid displaying tags which have less than X Posts?

the answer here is close Remove from Google Tags with less than 2 posts

however it suggests to send a respose header to google. I would ideally like to NOT have these tags in my sitemap so that google does not index these pages which are basically duplicates of the original post with a different tag, not a good thing for SEO!

1 Answer 1

2

Tags don't create duplicate posts, so the likelihood of them hurting your SEO by appearing in a sitemap are slim.

You can add a filter to the return of the taxonomies sitemap to remove tags. This is just a quick attempt I threw together. I haven't tested it but it should provide a basis to work from at the very least.

function remove_low_tags($taxonomies) {
   //create a new array of tags with count above 2
   array $allowed_tags;
   //loop through current array of tags and add them to $allowed_tags if they are > 2
   foreach ($taxonomies as $tags) {
      if (count($tags) > 2) {
         $allowed_tags[] = $tags;
      }
   }
   return $allowed_tags;
}
add_filter('wp_sitemaps_taxonomies', 'remove_low_tags');



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.