让wordpress网站的评论链接在新窗口打开与加nofollow

wordpress留言版块的评论链接和昵称链接如何实现新窗口打开,给wp的评论链接加上nofollow。


wordpress默认的是在本站打开,在WordPress评论中,会留下留言者的网址超链接,直接点击就会离开当前的页面,直接造成页面流量丢失,从而提高了网站的跳出率。让评论也像wp网站标题一样新窗口打开,这一点不仅仅对seo不利,而且也不符合用户体验。下面我们分别来说下wordpress评论链接新窗口打开和加nofollow。


 

wordpress实现评论链接新窗口打开

代码见:

找到:WP-include/comment-template.php      这个文件

然后在:function get_comment_author_link( $comment_ID = 0 ) {
/** @todo Only call these functions when they are needed. Include in if… else blocks */
$url    = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );

if ( empty( $url ) || ‘http://’ == $url )
$return = $author;
else
$return = “<a href=’$url’ rel=’external nofollow’ class=’url’ >$author</a>”;
return apply_filters(‘get_comment_author_link’, $return);
}

然后在找到:

$return = “<a href=’$url’ rel=’external nofollow’ class=’url’ >$author</a>”;
return apply_filters(‘get_comment_author_link’, $return);
}

加一个target=’_blank’

$return = “<a href=’$url’ rel=’external nofollow’ class=’url’ target=’_blank’>$author</a>”;
return apply_filters(‘get_comment_author_link’, $return);

文字说明如下:

首页打开wp-includes文件夹,找到comment-template.php文件打开。找到以下代码:

  1. $return = “<a href=’$url’ rel=’external nofollow’ class=’url’>$author</a>”;

在标签中插入一句[target="_blank"]尖括号中的内容,然后保存。这样,访客昵称所指向的链接就会在新窗口打开了。

当然,你也可以完全不让访客的昵称显示链接,就是将上面这行代码中$author前后的两个尖括号内的内容(a标签)直接删除。最后代码如下:

  1. $return = “$author”;

    评论链接加nofollow

    其实,让访客昵称带上链接更有利于吸引人气。况且,我们都看到了nofollow这个属性,就是说即使搜索引擎见到这个链接也不会追踪过去,更不会传递权重或者PR。google和百度都支持nofollow属性。

    在默认的WordPress模板中,我们看到评论人的留言链接网址都是设置成rel=’external nofollow’属性,如果你换的模板没有了的,你加上这个就行了,就这么简单。

米粒在线
  • 本文由 发表于 2012年9月7日22:48:23
  • 转载请务必保留本文链接:https://www.miliol.org/285.html
生活道理

熬夜如何改变了我们的身体

熬夜的危害有很多,如:经常感到疲劳,免疫力下降:人经常熬夜造成的后遗症,最严重的就是疲劳、精神不振;人体的免疫力也会跟着下降,感冒、胃肠感染、过敏等等自律神经失调症状都会出现。 头痛:熬夜的隔天,上班...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: