How to not display tags with less than X posts

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');