1、网站根目录新建 go
文件夹放入 index.php
文件,内容如下:
页面加载中,请稍候...
2、外链自动识别,在主题的 functions.php
文件中加入以下代码:
/*文章外部链接加上跳转*/
add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content)
{
preg_match_all('//',$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="".home_url()."/go/?url=$val" ",$content);
}
}
}
return $content;
}
/*评论处的链接新窗口打开并添加跳转*/
function get_comment_author_link_new($return, $author, $comment_ID = 0) {
$comment = get_comment( $comment_ID );
$url = get_comment_author_url( $comment );
$author = get_comment_author( $comment );
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "$author";
$return=str_replace("href='$url'", "href="".home_url()."/go/?url=$url" ",$return);//添加go跳转
return $return;
}
add_filter('get_comment_author_link', 'get_comment_author_link_new', 10, 3);
文章来源于互联网:WordPress站点自定义添加外链GO跳转