WordPress标签默认并无rel="nofollow"属性。rel="nofollow"属性的作用是:告诉搜索引擎,无需追踪目标页,禁止蜘蛛爬行和传递权重。如果你不准备让搜索收录标签,可以通过下面的代码为标签添加该属性。
将下面的代码添加到当前主题functions.php中:
- function cx_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>';
- }
- }
- }
用:
- <?php cx_tags(); ?>
替换主题模板中标签标准函数:
- <?php the_tags(); ?>
当然,你还可以在 rel="nofollow" 后面添加 target="_blank" 实现在新窗口或标签中打开链接。
参考:http://codex.wordpress.org/Function_Reference/get_the_tags
本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!

我的微信
微信号已复制
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!




