在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.111com.net");
exit;
}
}
}
|
在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽seo/seo.html" target="_blank">搜索引擎收录重定向后的网址
Disallow: /?r=*再来看看前台评论者的链接吧,都变成如下形式了
http://www.你的连接.com/?r=http://www.111com.net
但如果你的博客使用的是多说插件,那以上所有写的东西都是废话,没办法对多说里的评论起作用。
直接给WordPress评论连接加上nofollow功能
找到wordpress的functions.php(wwwrootwp-contentthemesConcisePro1.3),然后在其中添加以下代码,保存上传即可。
代码如下 |
复制代码 |
//评论加Nofollow
function add_nofollow_to_comments_popup_link(){
return ' rel="nofollow" ';
}
add_filter('comments_popup_link_attributes', 'add_nofollow_to_comments_popup_link');
|
顺便优化以下,要加的地方有两个,一个是评论者的链接,还有就是那个“回复”这也是个链接。
代码如下:
代码如下 |
复制代码 |
//为评论者添加nofollow属性
function add_nofollow_to_comments_popup_link(){
return 'rel="nofollow" ';
}
add_filter('comments_popup_link_attributes', 'add_nofollow_to_comments_popup_link');
//为评论回复链接加nofollow属性
add_filter('comment_reply_link', 'add_nofollow_to_replay_link');
function add_nofollow_to_replay_link( $link ){
return str_replace( '")'>', '")' rel='nofollow'>', $link );
}
|