网上找的外链跳转插件好几个,都不能用,要么没反应,要么不兼容,各种问题。就用ai弄了个测试,感觉效果不错就发到4414保存一下
首先,在自己的wordpress网站的根目录下新建一个go.php文件,在go.php里面输入以下代码(支持 Base64 ):
go.php:
<?php
if (!isset($_GET['url']) || empty($_GET['url'])) {
die('请勿直接打开本页面');
}
$url = trim($_GET['url']);
// 如果不是 http 开头,就 Base64 解密
if (!preg_match('/^https?:\/\//i', $url)) {
$url = base64_decode($url);
}
// 安全过滤
$url = htmlspecialchars(trim($url));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>即将离开网站</title>
<style>
html{background:#f4f5f5;}
#box{margin:10% auto;background:#fff;padding:10px 30px;max-width:500px;border:1px solid #e5e6eb;border-radius:2px;}
.note{font-size:18px;}
.link{padding:16px 0 24px;border-bottom:1px solid #e5e6eb;color:gray;word-break:break-all;}
.btn-plane{text-align:right;}
button{margin-top:20px;color:#fff;border-radius:3px;border:none;background:#007fff;height:32px;font-size:14px;padding:0 14px;cursor:pointer;}
button a{color:#fff;text-decoration:none;}
</style>
</head>
<body>
<div id="box">
<p>即将离开网站,请注意账号财产安全</p>
<p><?php echo $url; ?></p>
<p>
<button><a href="<?php echo $url; ?>" rel="nofollow">继续访问</a></button>
</p>
</div>
</body>
</html>JS 代码:自动给所有外链 Base64 加密,把这段代码放到你网站 页脚:
<script>
// 自动给外部链接做 Base64 加密跳转
(function(){
const host = window.location.hostname;
// 白名单:自己的域名,不加密跳转
const whitelist = [host, 'www.你自己的域名.com', '你自己的域名.com'];
// Base64 加密
function b64(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(match,p1){return String.fromCharCode('0x'+p1);}));}
// 遍历所有链接
document.querySelectorAll('a[href^="http"]').forEach(a=>{
let href = a.href.trim();
let h = new URL(href).hostname;
if(!whitelist.includes(h)){
// 外链:加密并跳转到 go.php
let encoded = b64(href);
a.href = '/go.php?url=' + encoded;
a.rel = 'nofollow';
}
});
})();
</script>效果(你想要的样子)原来的外链:
<a href="站外链接">百度</a>
自动变成:
<a href="/go.php?url=aHR0cHM6Ly93d3cuYmFpZHUuY29t">百度</a>
打开后: go.php 自动解密 → 显示跳转页面 → 正常跳去目标网站 完全隐藏真实 URL,非常干净!






