admin管理员组文章数量:1279085
I use the built in wp tag functionality to group my posts thematically and then I use the WP_query to have the posts displayed according to custom design. I do not need the tag pages created by default in wordpress and I would either like to have them NOT created at all (ideally) or be able to add a noindex meta to the post, as these should not be indexed separately. Is there some way to accomplish this?
EDIT: one additional possibility I have looked at is to exclude all matching urls from the sitemap eg exclude all urls matchine /tag/* . I use the Yoast plugin, but I don't see any filter which would allow me to do this type of exclusion.
I use the built in wp tag functionality to group my posts thematically and then I use the WP_query to have the posts displayed according to custom design. I do not need the tag pages created by default in wordpress and I would either like to have them NOT created at all (ideally) or be able to add a noindex meta to the post, as these should not be indexed separately. Is there some way to accomplish this?
EDIT: one additional possibility I have looked at is to exclude all matching urls from the sitemap eg exclude all urls matchine /tag/* . I use the Yoast plugin, but I don't see any filter which would allow me to do this type of exclusion.
Share Improve this question edited Nov 16, 2021 at 17:14 shelbypereira asked Nov 16, 2021 at 13:18 shelbypereirashelbypereira 1375 bronze badges1 Answer
Reset to default 1To redirect from the automatically-generated tag archive pages, you can check to see if is_tag()
is true in the template_redirect
action hook, and redirect with wp_redirect()
if it is:
add_action( 'template_redirect', function() {
if ( is_tag() ) {
// Currently redirects to the site's home page.
wp_redirect( '/' );
// Use the 301 Permanent redirect if desired.
// wp_redirect( '/', 301 );
exit;
}
} );
To exclude the tags from the sitemap generated by WordPress (Plan B in your question), you can use the wp_sitemaps_taxonomies
filter.
add_filter( 'wp_sitemaps_taxonomies', function( $taxonomies ) {
if ( ! empty( $taxonomies['post_tag'] ) ) {
unset( $taxonomies['post_tag'] );
}
return $taxonomies;
} );
本文标签: How can I prevent wordpress from creating tag pages
版权声明:本文标题:How can I prevent wordpress from creating tag pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741217455a2360321.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论