关于给wordpress的tag加上nofollow属性

偶尔在google上看了一下自己站点的收录信息:简直一塌糊涂啊.标签页,page页,图像页等等全都给收录进去了,以前还觉得收录越多越好,都是年轻的时候犯的大错,居然要长大的自己来承担,所以今天给tag做了小小的优化,为A链接添加nofollow属性.

废话不多说上代码

//为tag cloud添加nofollow
function szub_nofollow_tag($text) {
    return str_replace('<a href=', '<a rel="nofollow" href=',  $text);    
}
add_filter('wp_tag_cloud', 'szub_nofollow_tag');
//为archive页面tag添加nofollow
function nofollow_tags() {
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            echo '<a class="tag-link' . $tag->term_id . '" href="'.get_tag_link($tag).'" rel="nofollow">'.$tag->name.'</a>';
        }
    }
}

在format-standard.php中找到tag的输出位置,将输出函数替换为nofollow_tags()

7 thoughts on “关于给wordpress的tag加上nofollow属性”

Leave a Reply to www.last.city Cancel reply

Your email address will not be published. Required fields are marked *