给WordPress的评论链接加上nofollow属性

老牛注释:慎用此方法!在最新版本的wordpress上无效,还会导致网站出500错误,后台也无法进入,解决方法,登陆主机后台,使用在线文件管理器,在线编辑你所使用的模板目录下function.php,删除添加的代码即可恢复。

或许你已经找到生成评论链接的方法: comments_popup_link.并准备如同处理 Read more 一样为链接加上 nofollow, 但是最终发现这个方法不能使用 filter. 是的, 这个方式不能这样搞, 三年前就有人认为这是一个 bug 了.

其实不然, 该方法在打印 a 标签的 title 属性前有以下语句:

echo apply_filters( ‘comments_popup_link_attributes’, ” );

什么意思? 说明可以通过 comments_popup_link_attributes 为链接加上其他属性. 所以我们可以在 function.php 或者在插件中加入以下代码来为 WordPress 的评论链接加上 nofollow:

function add_nofollow_to_comments_popup_link(){

return ‘ rel=”nofollow” ‘;

}

add_filter(‘comments_popup_link_attributes’, ‘add_nofollow_to_comments_popup_link’);

通过为 WordPress 的评论链接加上 nofollow.

原文链接:https://xiaohost.com/105.html,转载请注明出处。
0

评论0

请先