WordPress Comments Link Redirect 插件是把评论者的链接或留言链接的 URL 转化为一个跳转链接URL,如:
http://www.superm.org/?r=http://评论者的URL
之前一直不知道是哪里设置,后来在万戈的WordPress 评论链接重定向跳转文章中看到了解决方案,在这里推荐用水煮鱼的Comments Link Redirect插件。称之为防 Spam 的终极办法。为什么说是终极防Spam的办法呢?因为这样设置之后,就算Spam成功留言了,也不会被搜索引擎索引。下面来说说wordpress Comments Link Redirect的使用方法。
其实这个插件方法很简单,首先下载Comments Link Redirect,然后上传到wp-content/plugins/中,wordpress后台启用,再刷新看看是不是转换成了上面的那种跳转方式啦?~
如果不想使用插件的童鞋,可以直接在主题文件中找到functions.php,添加下面代码:
//comments link redirect
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.superm.org/");
exit;
}
}
}
添加好之后上传,再任意刷新你的wordpress文章,看看评论是不是变成:
http://www.superm.org/?r=http://评论者的URL
这样的链接啦?最后还需要在robots.txt文件中添加:
Disallow: /?r=*
好了,没有动手的童鞋快快动手吧!
67 评论
添加评论