wordpress go跳转实现办法

首先将以下代码放入wordpress主题根目录下的function.php文件最底部

/**
* WordPress外链新窗口打开并使用php页面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目录,新增一个index.php的文件,将下面的代码放入html代码的头部位置

<?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='//www.jxip.net/';
	        $title='参数错误,正在返回首页';
	    }
	}
} else {
    $title='参数缺失,正在返回首页';
    $url='//www.jxip.net/';
}
?>

html的文件,其实你们可以随便写。。主要还是一个跳转和自动跳转的问题,这里放两个,一个是仿造知乎的不自动跳转的页面

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="robots" content="noindex">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title><?php echo $title;?></title>
    <style>
        body,
        h1,
        p {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
        }

        button {
            padding: 0;
            font-family: inherit;
            background: none;
            border: none;
            outline: none;
            cursor: pointer;
        }

        html {
            width: 100%;
            height: 100%;
            background-color: #eff2f5;
        }

        body {
            padding-top: 100px;
            color: #222;
            font-size: 13px;
            font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
            line-height: 1.5;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        }

        @media (max-width: 620px) {
            body {
                font-size: 15px;
            }
        }

        .button {
            display: inline-block;
            padding: 10px 16px;
            color: #fff;
            font-size: 14px;
            line-height: 1;
            background-color: #0077d9;
            border-radius: 3px;
        }

        @media (max-width: 620px) {
            .button {
                font-size: 16px;
            }
        }

        .button:hover {
            background-color: #0070cd;
        }

        .button:active {
            background-color: #0077d9;
        }

        .link-button {
            color: #105cb6;
            font-size: 13px;
        }

        @media (max-width: 620px) {
            .link-button {
                font-size: 15px;
            }
        }

        .logo,
        .wrapper {
            margin: auto;
            padding-left: 30px;
            padding-right: 30px;
            max-width: 540px;
        }

        .wrapper {
            padding-top: 25px;
            padding-bottom: 25px;
            background-color: #f7f7f7;
            border: 1px solid #babbbc;
            border-radius: 5px;
        }

        @media (max-width: 620px) {
            .logo,
            .wrapper {
                margin: 0 10px;
            }
        }

        h1 {
            margin-bottom: 12px;
            font-size: 16px;
            font-weight: 700;
            line-height: 1;
        }

        @media (max-width: 620px) {
            h1 {
                font-size: 18px;
            }
        }

        .warning {
            color: #c33;
        }

        .link {
            margin-top: 12px;
            word-wrap: normal;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            cursor: pointer;
        }

        .link.is-expanded {
            word-wrap: break-word;
            white-space: normal;
        }

        .actions {
            margin-top: 15px;
            padding-top: 30px;
            text-align: right;
            border-top: 1px solid #d8d8d8;
        }

        .actions .link-button + .link-button {
            margin-left: 30px;
        }

        .tip {
            position: relative;
            display: none;
            margin-top: 30px;
            padding-top: 18px;
            color: #999;
            text-align: left;
            background: #f7f7f7;
            border-top: 1px solid #d8d8d8;
            opacity: 0;
            transition: opacity .2s ease-out;
        }

        .tip.is-visible {
            opacity: 1;
        }

        .tip:after, .tip:before {
            position: absolute;
            bottom: 100%;
            right: 5em;
            content: " ";
            height: 0;
            width: 0;
            border: solid transparent;
            pointer-events: none;
        }

        .tip:after {
            margin-right: -6px;
            border-color: rgba(247, 247, 247, 0);
            border-bottom-color: #f7f7f7;
            border-width: 6px;
        }

        .tip:before {
            margin-right: -7px;
            border-color: rgba(216, 216, 216, 0);
            border-bottom-color: #d2d2d2;
            border-width: 7px;
        }
    </style>
</head>
<body>
<div class="logo">
    <a href="https://www.jxip.net">
        <img src="https://www.jxip.net/wp-content/uploads/2021/10/1634438652-logo.png"
             srcset="https://www.jxip.net/wp-content/uploads/2021/10/1634438652-logo.png 2x" alt="图图网">
    </a>
</div>
<div class="wrapper">
    <div class="content">
        <h1>即将离开图图网</h1>
        <p class="info">您即将离开图图网,请注意您的帐号和财产安全。</p>
        <p class="link"><?php echo $url;?></p>
    </div>
    <div class="actions">
        <a class="button" href="https://www.jxip.net">返回首页</a>
        <a class="button" href="<?php echo $url;?>">继续访问</a>
    </div>
</div>
<script>
    var showTipButton = document.querySelector('.js-show-tip');
    var tipEl = document.querySelector('.tip');
    var showTip = function () {
        tipEl.style.display = 'block';
        tipEl.offsetWidth; // force reflow
        tipEl.className = 'tip is-visible';
        return false;
    };

    var linkEl = document.querySelector('.link');
    var selectLink = function () {
        linkEl.className = 'link is-expanded';
        if (document.body.createTextRange) {
            range = document.body.createTextRange();
            range.moveToElementText(linkEl);
            range.select();
        } else if (window.getSelection) {
            selection = window.getSelection();
            range = document.createRange();
            range.selectNodeContents(linkEl);
            selection.removeAllRanges();
            selection.addRange(range);
        }
        ;
    };

    if (window.addEventListener) {
        showTipButton.addEventListener('click', showTip);
        linkEl.addEventListener('click', selectLink);
    } else {
        showTipButton.attachEvent('onclick', showTip);
        linkEl.attachEvent('onclick', selectLink);
    }
</script>
</body>
</html>

另外下面这个是一个loading自动跳转的动画,至于跳转时间,可以在meta下面 content="2 那啥里面修改

<!--
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height, initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes"> 
<meta name="robots" content="noindex,follow">
<title>加载中</title>
 <meta http-equiv="refresh" content="2;url='<?php echo $url;?>';">
<style>
body{font-weight:100;margin:0}body{-webkit-tap-highlight-color:transparent;background-color:#222428;font-size:100%;font-family:Open Sans;height:100%}.loader{top:50%;left:50%;-webkit-transform:translate(-50%,-50%);-mos-transform:translate(-50%,-50%);transform:translate(-50%,-50%);text-align:center;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default;width:80%;overflow:visible}.loader,.loader div{position:absolute;height:36px}.loader div{width:30px;margin:0 10px;opacity:0;animation:move 2s linear infinite;-o-animation:move 2s linear infinite;-moz-animation:move 2s linear infinite;-webkit-animation:move 2s linear infinite;transform:rotate(180deg);-o-transform:rotate(180deg);-moz-transform:rotate(180deg);-webkit-transform:rotate(180deg);color:#fff;font-size:3em}.loader div:nth-child(8):before{background:#db2f00}.loader div:nth-child(8):before,.loader div:nth-child(9):before{content:'';position:absolute;bottom:-15px;left:0;width:30px;height:30px;border-radius:100%}.loader div:nth-child(9):before{background:#f2f2f2}.loader div:nth-child(10):before{bottom:-15px;height:30px;background:#13a3a5}.loader div:after,.loader div:nth-child(10):before{content:'';position:absolute;left:0;width:30px;border-radius:100%}.loader div:after{bottom:-40px;height:5px;background:#39312d}.loader div:nth-child(2){animation-delay:.2s;-o-animation-delay:.2s;-moz-animation-delay:.2s;-webkit-animation-delay:.2s}.loader div:nth-child(3){animation-delay:.4s;-o-animation-delay:.4s;-webkit-animation-delay:.4s}.loader div:nth-child(4){animation-delay:.6s;-o-animation-delay:.6s;-moz-animation-delay:.6s;-webkit-animation-delay:.6s}.loader div:nth-child(5){animation-delay:.8s;-o-animation-delay:.8s;-moz-animation-delay:.8s;-webkit-animation-delay:.8s}.loader div:nth-child(6){animation-delay:1s;-o-animation-delay:1s;-moz-animation-delay:1s;-webkit-animation-delay:1s}.loader div:nth-child(7){animation-delay:1.2s;-o-animation-delay:1.2s;-moz-animation-delay:1.2s;-webkit-animation-delay:1.2s}.loader div:nth-child(8){animation-delay:1.4s;-o-animation-delay:1.4s;-moz-animation-delay:1.4s;-webkit-animation-delay:1.4s}.loader div:nth-child(9){animation-delay:1.6s;-o-animation-delay:1.6s;-moz-animation-delay:1.6s;-webkit-animation-delay:1.6s}.loader div:nth-child(10){animation-delay:1.8s;-o-animation-delay:1.8s;-moz-animation-delay:1.8s;-webkit-animation-delay:1.8s}@keyframes move{0%{right:0;opacity:0}35%{right:41%}35%,65%{-webkit-transform:rotate(0);transform:rotate(0);opacity:1}65%{right:59%}to{right:100%;-webkit-transform:rotate(-180deg);transform:rotate(-180deg)}}@-webkit-keyframes move{0%,to{opacity:0}0%{right:0}35%{right:41%}35%,75%{-webkit-transform:rotate(0);transform:rotate(0);opacity:1}75%{right:59%}to{right:100%;-webkit-transform:rotate(-180deg);transform:rotate(-180deg);opacity:0}}
</style>
</head>
<body class="ie8">
    <div class="loader">
        <div> L </div>
        <div> O </div>
        <div> A </div>
        <div> D </div>
        <div> I </div>
        <div> N </div>
        <div> G </div>
        <div> </div>
        <div> </div>
        <div> </div>
    </div>
</body>
</html>

注意哦,上面的php代码和下面的html代码是放一起的,不然链接会识别不出来,老手可以不看,新手必看哦

下面举个例子:

跳转到图图网首页(咳 翻车 本站不会跳)

跳转到百度首页

给TA买糖
共{{data.count}}人
人已赞赏
wordpress

wordpress tags标签内链无需插件

2021-10-29 10:58:22

快讯

哔哩哔哩推出视频编辑APP“必剪” 支持作品直接发送至B站

2020-7-27 19:38:46

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索