1、把下面代码复制并保存为一个 index.php文件,然后在网站根目录新建一个go文件夹,把 index.php拖到网站根目录的go文件夹;然后(搜索$myDomain = ‘zahuozhijia.com’; 修改为自己的顶级域名)。注意,这里不加www或者其他,只添加顶级域名比如 baidu.com 而不是 www.baidu.com。
这里需要另外说明的一点是你也可以直接保存为go.php上传到网站根目录下,后面修改链接的时候将 go 替换成 go.php 就行了。
我直接打包好了index.php文件
2、将下面代码放入你主题的 functions.php 文件中
文章内外链添加go跳转:
//文章内外链添加go跳转
function the_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=\"".home_url()."/go/?url=$val\" ",$content);
}
}
}
return $content;
}
add_filter('the_content','the_content_nofollow',999);
评论者链接添加go跳转:
//评论者链接添加go跳转
function add_redirect_comment_link($text = ''){
$text=str_replace('href="',%20'href="'.get_option('home').'/go/?url=', $text);
return $text;
}
add_filter('get_comment_author_link', 'add_redirect_comment_link', 5);
add_filter('comment_text', 'add_redirect_comment_link', 99);
如果你直接将 Go 页面代码保存成 go.php 的话记得改一下上面链接~
感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
暂无评论内容