WordPress文章外链添加go跳转

如题所述,以下代码就可以帮助大概解决这个问题,找到你主题目录下的”functions.php”文件,添加以下代码上传覆盖即可。

/*-----------------------------------------------------------------------------------*/
/* WordPress文章内外链添加go跳转
/*-----------------------------------------------------------------------------------*/
function loper_content_nofollow($content){
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href=\"$val\"", "href=\"".get_stylesheet_directory_uri()."/go.php?url=$val\" ",$content);
}
}
}
return $content;
}
add_filter('the_content','loper_content_nofollow',999);

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

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

(10)个小伙伴在吐槽
  1. Best Drug Rehab http://aaa-rehab.com Drug Rehab Near Me Drug Rehab Centers http://sanatoriyakzhaik.kz/user/drugrehabds/
    Alcohol Abuse Help Near Me2020-04-01 16:08 Windows 7 | Chrome 67.0.3396.87
  2. Best Drug Rehab http://aaa-rehab.com Drug Rehab Near Me Drug Rehab Centers http://sanatoriyakzhaik.kz/user/drugrehabds/
    Alcohol Abuse Help Near Me2020-04-01 16:08 Windows 7 | Chrome 67.0.3396.87
  3. Best Drug Rehab http://aaa-rehab.com Drug Rehab Near Me Drug Rehab Centers http://sanatoriyakzhaik.kz/user/drugrehabds/
    Alcohol Abuse Help Near Me2020-04-01 16:08 Windows 7 | Chrome 67.0.3396.87
  4. Medical Drug Rehab http://aaa-rehab.com Drug Rehab Centers Inpatient Drug Treatment Centers https://buzzon.khaleejtimes.com/author/airfuel3/
    Teen Substance Abuse2020-04-01 00:18 Windows 8.1 | Chrome 68.0.3440.106
  5. Medical Drug Rehab http://aaa-rehab.com Drug Rehab Centers Inpatient Drug Treatment Centers https://buzzon.khaleejtimes.com/author/airfuel3/
    Teen Substance Abuse2020-04-01 00:16 Windows 8.1 | Chrome 68.0.3440.106
  6. Medical Drug Rehab http://aaa-rehab.com Drug Rehab Centers Inpatient Drug Treatment Centers https://buzzon.khaleejtimes.com/author/airfuel3/
    Teen Substance Abuse2020-04-01 00:15 Windows 8.1 | Chrome 68.0.3440.106
  7. Medical Drug Rehab http://aaa-rehab.com Drug Rehab Centers Inpatient Drug Treatment Centers https://buzzon.khaleejtimes.com/author/airfuel3/
    Teen Substance Abuse2020-04-01 00:14 Windows 8.1 | Chrome 68.0.3440.106
  8. Prevention Of Alcohol Abuse http://aaa-rehab.com Drug Rehab Near Me Women'S Rehab Center https://www.4x4brasil.com.br/forum/members/165949-arehabs.html
    Alcohol Abuse Counseling2020-03-31 07:38 Windows 7 | Chrome 67.0.3396.87
  9. Alcohol Abuse Help Near Me http://aaa-rehab.com Drug Rehab Centers Near Me Free Rehab Facilities Near Me https://cryptoforumtalk.org/member.php?action=profile&uid=9489
    Mat Substance Abuse2020-03-30 16:03 Windows 10 | Chrome 67.0.3396.87
  10. Outpatient Alcohol Rehab Near Me http://aaa-rehab.com Drug Rehab http://aaa-rehab.com Drug Rehabs That Take Medicaid http://aaa-rehab.com
    Free Rehabilitation Centres2020-03-27 07:21 Windows 7 | Chrome 66.0.3359.181