admin管理员组

文章数量:1122846

As we are noindexing all the Tag archives, this sometimes creates a lot of warnings in the Google GSC panel because the Google bot tries to follow the Tag hyperlinks and sees the noindex meta tag, and then it generates hundreds of warnings in the category of Excluded by 'noindex' tag since the Tag links are public on the posts.

I'm hoping to customize get_the_tags to add rel="nofollow" to every Tag archive hyperlink... and also for the Tag Cloud widget too if possible.

As we are noindexing all the Tag archives, this sometimes creates a lot of warnings in the Google GSC panel because the Google bot tries to follow the Tag hyperlinks and sees the noindex meta tag, and then it generates hundreds of warnings in the category of Excluded by 'noindex' tag since the Tag links are public on the posts.

I'm hoping to customize get_the_tags to add rel="nofollow" to every Tag archive hyperlink... and also for the Tag Cloud widget too if possible.

Share Improve this question asked Jul 22, 2024 at 5:02 Jesse NicklesJesse Nickles 7357 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I already had this challenge before and here is my personal solution for you:

1. For the tag cloud widget you can use this approach:

add_filter('wp_tag_cloud', 'add_nofollow_to_tag_cloud');
function add_nofollow_to_tag_cloud($content) {
    // Add 'nofollow' to the links
    $content = str_replace('<a href="', '<a rel="nofollow" href="', $content);
    return $content;
}

I already tested this locally and it works fine.

2. For the get_the_tags() function you can add this function:

add_filter('term_links-post_tag', 'add_nofollow_to_tag_list');
function add_nofollow_to_tag_list($tag_list) {
    $tag_list = str_replace('<a href="', '<a rel="nofollow" href="', $tag_list);
    return $tag_list;
}

The outcome will be the same:

本文标签: seoHow to add 39nofollow39 flag to all Tag archive hyperlinks