WordPress评论者链接重定向且在新窗口打开

付费节点推荐

免费节点

节点使用教程

Clash 小火箭 v2ray节点购买

好用的梯子,海外网络,快速稳定

Google

经常在一些朋友的博客上看到,当鼠标移动到评论者上时,浏览器的状态栏显示的地址是这样子的格式:http://www.59iwp.com/?to=http://newrul,网上有人说这样子每个评论就是一个外链,会分散网站权重,虽然不知道是否属实,但正好前两天有人咨询了珞凡关于Wordpress评论者链接重定向且在新窗口打开的方法,所以,今天在这里就简单说下实现方法的文章吧。

打开我们的主题目录,找到functions.php,在适当位置加上下面的代码(这个适当位置够模糊,如果你不确定哪个地方算是适当位置,也可以直接加在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: 你的网址/”);
exit;
}
}
}

以上,保存并刷新网页,完工。

该文章由WP-AutoPost插件自动采集发布

原文地址:http://www.59iwp.com/254.html

更多资源请订阅公众号:bcoder

bcoder

相关文章

评论(0)
游客的头像
表情
全部评论
最新