Loading...

OneNav主题-网站外链-添加Go界面跳转

教程分享2年前 (2022)更新 战东海
322 0 0

介绍一个网站自定义Go界面跳转网址外链功能。有些主题自带此功能:比如mkBlog主题(在SEO设置里)。如果你想自定义Go界面跳转外链,你可以参考一下此内容,只需两步即可完成。

一、添加go.php文件

新建go.php文件,写入以下代码,之后复制到网站根目录

<?php 
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]); 
if(!empty($t_url)) {
preg_match('/(http|https):\/\//',$t_url,$matches);
if($matches){
$url=$t_url;
$title='页面正在安全跳转中,请稍候';
} else {
preg_match('/\./i',$t_url,$matche);
if($matche){
$url='http://'.$t_url;
$title='页面正在安全跳转中,请稍候';
} else {
$url='//defcon.cn/';
$title='参数错误,正在返回首页';
}
}
} else {
$title='参数缺失,正在返回首页';
$url='//defcon.cn/';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="1;url='<?php echo $url;?>';">
</head>
<body>
跳转画面内容...
</body>
</html>

将想要的显示的界面代码填入,收集了三种样式见文末。

二、添加function代码

在当前主题的functions.php内添加如下代码

add_filter('the_content','the_content_nofollow',999);
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.php?url=$val\" ",$content);
}
}
}
return $content;
}

三、代码文件下载

链接: https://pan.baidu.com/s/1mYM1j7j7AOicaQVUEZVOtQ?pwd=jefg 提取码: jefg 复制这段内容后打开百度网盘手机App,操作更方便哦

OneNav主题-网站外链-添加Go界面跳转 OneNav主题-网站外链-添加Go界面跳转 OneNav主题-网站外链-添加Go界面跳转如果有好看的代码,可以留言补充哦~

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...

网址设置

网址样式切换

详细

网址卡片按钮

显示

布局设置

左侧边栏菜单

展开

搜索框设置

自定义搜索框背景

  • 骑行

  • 风景

自定义搜索框高度

  • 聚焦
  • 信息
  • 默认
自定义设置
TAB栏自定义颜色

背景颜色

文字颜色