To 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( "https://wordpress.stackexchange.com/" );
// Use the 301 Permanent redirect if desired.
// wp_redirect( "https://wordpress.stackexchange.com/", 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;
} );