WordPress文章外链添加go跳转

/* 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); //根据go文件的位置调整
}
}
}
return $content;
}
add_filter('the_content','loper_content_nofollow',999);
/**
/* WordPress评论外链添加go跳转
*/
function loper_redirect_comment_link($text = ''){
$text = str_replace('href="', 'href="' . get_stylesheet_directory_uri() . '/go.php?url=', $text); //根据go文件的位置调整
$text = str_replace("href='", "href='" . get_stylesheet_directory_uri() . "/go.php?url=", $text); //根据go文件的位置调整
return $text;
}
add_filter('get_comment_author_link', 'loper_redirect_comment_link', 5);
add_filter('comment_text', 'loper_redirect_comment_link', 99);

 

© 版权声明
THE END
喜欢就支持一下吧
分享
评论 抢沙发

    暂无评论内容