wordpress技巧:为标签链接添加rel=”nofollow”属性

  • 时间:2020-05-23 15:34:29
  • 分类:网络文摘
  • 阅读:92 次

出于seo的需要,有时候我们可能不希望标签链接被搜索引挚收录,可以在链接中多加一个属性 rel="nofollow" ,它的作用是告诉搜索引擎无需抓取并追踪此链接,禁止蜘蛛爬行并传递权重。但wordpress标签本身并无 rel="nofollow" 属性,想要实现这一点,可以通过下面的wordpress技巧:

wordpress技巧:为标签链接添加rel="nofollow"属性

1、添加如下代码添加到wordpress主题的functions.php文件中:

  1. function cx_tags() {
  2.     $posttags = get_the_tags();
  3.     if ($posttags) {
  4.         foreach($posttags as $tag) {
  5.             echo '<a class="tag-link' . $tag->term_id . '" href="http://uuxn.com/wordpress-tag-add-rel-nofollow/'.get_tag_link($tag).'" rel="nofollow">'.$tag->name.'</a>';
  6.         }
  7.     }
  8. }

2、用下面的函数:

  1. <?php cx_tags(); ?>

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

  1. <?php the_tags(); ?>

此外:如果想让标签链接在新窗口或标签中打开,可以在 rel="nofollow" 后面添加 target="_blank" 。

官方参考文档:http://codex.wordpress.org/Function_Reference/get_the_tags

推荐阅读:
大米的分类、营养价值与营养功效  营养盘点:各种米饭的神奇养生功效  预防酒糟鼻的饮食疗法有哪些?  教大家自制四款降火粥给身体降火  适当吃些辣椒的6大保健养生功效  保健养生:盘点草莓的六大养生功效  春天最好少吃这几种反季节水果  牛奶和酸奶,到底哪个更有营养呢?  健康与饮食:养胃护胃之八大饮食禁忌  关于饮用牛奶饮品的六个健康误区 
评论列表
添加评论