【wordpress教程】給外部鏈接加上跳轉 代碼篇

wordpress給外部鏈接加上跳轉 代碼篇,直接將該代碼插入到主題目錄裏functions.php 文件內即可

//給外部鏈接加上跳轉  
function git_go_url($content){  
    preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);  
    if($matches && !is_page('about')){  
        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)){  
                if(git_get_option('git_pagehtml_b')) {  
                    $content=str_replace("href=\"$val\"", "href=\"".home_url()."/go.html/?url=$val\" ",$content);  
                }else{  
                    $content=str_replace("href=\"$val\"", "href=\"".home_url()."/go/?url=$val\" ",$content);  
                }  
            }  
        }  
    }  
    return $content;  
}  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章