用WP建了网站之后,免不了会收到一些垃圾评论及链接,在使wordpress评论的链接在新窗口打开中讲的是修改wordpress源文件使之在新窗口打开,当然它本身也添加了代码:rel='external nofollow' 屏蔽传递权重。
但大多链接里全是广告,可以用以下方式来去除wordpress评论中的网址栏:
找到当下主题的functions.php文件,添加如下代码:
function remove_comment_fields($fields) {
unset($fields['url']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
保存后查看,网址栏已经去除~!
如果你的主题没有为评论和回复添加nofollow标签,可以为你主题添加如下代码屏蔽权重分散(同样是在主题的functions.php里面):
//为评论者添加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 );
}
同样修改主题文件使评论链接重定向及在新窗口打开可以使用以下代码:
//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://aikenote.com/");
exit;
}
}
}
OK搞定所有从源码及主题文件修改评论者链接重定向及新窗口打开,当然也可以使用其他方法,比如JQuery等。