首页 > CMS教程 > WordPress    日期:2018-08-29 / 来自互联网 / 浏览

在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

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

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章