网站添加Go界面跳转

介绍一个网站自定义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;
}

其中go.php?url=可以修改成其他格式,如go/?url=。但go.php的保存位置和名称也要改成/go/index.php。

三、代码文件下载




以上三种样式代码下载:https://www.jishusongshu.com/wordpress-site/go-jump-link/
如果有好看的代码,可以留言补充哦~

本文采用 CC BY-NC-SA 3.0 Unported 许可,转载请以超链接注明出处。
原文地址:网站添加Go界面跳转 作者:松鼠小
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
Source: Telegram @AmashiroNatsukiEars_NoWord Sticker
Source: Github @zhheo/Sticker-Heo
Source: github.com/k4yt3x/flowerhd
颜文字
AmashiroNatsukiEars
Heo
小恐龙
花!
下一篇