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 badges1 Answer
Reset to default 2Tags 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
版权声明:本文标题:wp query - How to not display tags with less than X posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741251070a2365798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论