- A+
所属分类:WordPress教程
教程介绍
为什么要给评论链接添加一个跳转页面那?最近我发现我网站很多评论者的网站没能继续坚持做下去下(关站了),这样就造成了很多死链,但是这样很有可能影响自己网站的SEO。虽然加了nofollow标签,但是百度,360,搜狗到底遵守没有很难说。所以给WordPress评论链接添加跳转页面是很有必要的。
添加方法
1.将以下代码添加到当前使用主题的functions.php文件中即可。
-
//评论者链接重定向
-
add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
-
add_filter('comment_text', 'add_redirect_comment_link', 99);
-
function add_redirect_comment_link($text = ''){
-
$text=str_replace('href="', 'href="'.get_option('home').'/go/?url=', $text);
-
$text=str_replace("href='", "href='".get_option('home')."/go/?url=", $text);
-
return $text;
-
}
2.下载index.php文件 (备注:下载后请修改后缀名zip为php)
3.在网站的根目录创建一个go文件夹,并把index.php上传进去即可。
PS:记得在robots.txt文本中添加 Disallow: /go/
[idl id="95" t="下载index.php文件"] 暂无演示 | 下载index.php文件(下载后请修改后缀名zip为php)[/idl]