为 WordPress 标签添加 rel="nofollow" 属性

WordPress 标签默认并无 rel="nofollow" 属性。rel="nofollow" 属性的作用是:告诉搜索引擎,无需追踪目标页,禁止蜘蛛爬行和传递权重。如果你不准备让搜索收录标签,可以通过下面的代码为标签添加该属性。

将下面的代码添加到当前主题 functions.php 中:

function kim_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>';
        }
    }
}

然后用:

kim_tags();

替换主题模板中标签标准函数:

the_tags();

当然,你还可以在 rel="nofollow" 后面添加 target="_blank" 实现在新窗口或标签中打开链接。

posted @ 2016-11-02 12:05  幻月无名  阅读(338)  评论(0编辑  收藏  举报