admin管理员组

文章数量:1287661

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!

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!

Share Improve this question asked Oct 26, 2021 at 13:12 shelbypereirashelbypereira 1375 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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');



本文标签: wp queryHow to not display tags with less than X posts