wordpress给外部链接加上跳转 代码篇

2019年12月22日19:22:28 发表评论 热度215 ℃

wordpress给外部链接加上跳转 代码篇,直接将该代码插入到主题目录里functions.php 文件内即可,包爽,呵呵大!!!

  1. //给外部链接加上跳转  
  2. function git_go_url($content){  
  3.     preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);  
  4.     if($matches && !is_page('about')){  
  5.         foreach($matches[2] as $val){  
  6.             if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){  
  7.                 if(git_get_option('git_pagehtml_b')) {  
  8.                     $content=str_replace("href=\"$val\"""href=\"".home_url()."/go.html/?url=$val\" ",$content);  
  9.                 }else{  
  10.                     $content=str_replace("href=\"$val\"""href=\"".home_url()."/go/?url=$val\" ",$content);  
  11.                 }  
  12.             }  
  13.         }  
  14.     }  
  15.     return $content;  
  16. }  
瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: