WordPress文章外链添加go跳转

WordPress 云上的幻象 2个月前 (02-01) 89次浏览 3个评论 扫描二维码

如题所述,以下代码就可以帮助大概解决这个问题,找到你主题目录下的”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);
喜欢 (0)
[[email protected]]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(3)个小伙伴在吐槽
  1. 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 (3小时前)回复 Windows 7 | Chrome 67.0.3396.87
  2. 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 (19小时前)回复 Windows 10 | Chrome 67.0.3396.87
  3. 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 (4天前)回复 Windows 7 | Chrome 66.0.3359.181