wp给文章评论添加go跳转

今天来说说,wordpress如何给文章评论里的链接,添加go跳转,使其有利于SEO。首先找到模板文件中的“functions.php”添加以下代码:

// 评论链接url跳转
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="', 'target="_blank" href="'.get_option('home').'/go.php?url=', $text );
$text = str_replace("href='", "target='_blank'href='".get_option('home')."/go.php?url=", $text );
return $text;
}
add_action('init', 'redirect_comment_link');
function redirect_comment_link(){
$redirect = $_GET['url'];
if($redirect){
if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
header("Location: $redirect");
exit;
}
else {
header("Location: http://www.qicaiyun.top/"); // 此处!请修改成自己的链接
exit;
}
}
}

需要注意的是:

$text = str_replace('href="', 'target="_blank" href="'.get_option('home').'/go.php?url=', $text );
$text = str_replace("href='", "target='_blank'href='".get_option('home')."/go.php?url=", $text );


有的人使用的是静态页面,所以应把/go.php?url= 改为/go.html?url=,否则会跳转不成功。至于go.php内代码,网上一大堆,请自行百度吧。


七彩云博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:wp给文章评论添加go跳转

您必须 登录 才能发表评论!

(5)个小伙伴在吐槽
  1. Opioid Rehab Centers Near Me http://aaa-rehab.com Drug Rehab Centers Near Me Closest Methadone Clinic To Me https://www.google.co.zm/url?q=http://aaa-rehab.com
    Medical Rehab Centers2020-04-01 03:36 Windows 7 | Chrome 66.0.3359.181
  2. Samhsa Substance Abuse http://aaa-rehab.com Alcohol Rehab Near Me Substance Abuse Treatment Centers Near Me http://3.cncal.com/home.php?mod=space&uid=456721
    Best Rehab Near Me2020-03-31 11:19 Windows 10 | Chrome 66.0.3359.170
  3. Local Drug Treatment Centers http://aaa-rehab.com Drug Rehab Centers Free Rehabilitation Centres http://decoratorsheaven.com/user/profile/19152
    Drug Abuse Treatment Centers Near Me2020-03-30 19:08 Windows 7 | Chrome 68.0.3440.106
  4. Substance Use Assessment http://aaa-rehab.com Drug Rehab Centers Suboxone Rehab https://www.vingle.net/posts/2825279
    Inpatient Drug Treatment Centers Near Me2020-03-30 03:39 Windows 10 | Chrome 64.0.3282.140
  5. Drug Rehabilitation Center http://aaa-rehab.com Drug Rehab Centers Near Me http://aaa-rehab.com Drug Rehab Clinics Near Me http://aaa-rehab.com
    Drug Rehab Programs2020-03-26 06:27 Windows 7 | Chrome 67.0.3396.99