在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")."/?r=", $text);
$text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
return $text;
}
add_action("init", "redirect_comment_link");
function redirect_comment_link(){
$redirect = $_GET["r"];
if($redirect){
if(strpos($_SERVER["HTTP_REFERER"],get_option("home")) !== false){
header("Location: $redirect");
exit;
}
else {
header("Location: http://www.sjyhome.com/");
exit;
}
}
}

在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽搜索引擎收录重定向后的网址

Disallow:?/?r=*

再来看看前台评论者的链接吧,都变成如下形式了

http://www.freexyz.cn/?r=http://www.xxx.com

但如果你的博客使用的是多说插件,那以上所有写的东西都是废话,没办法对多说里的评论起作用。


WordPress

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。