wordpress官网中文

WordPress 纯代码实现外链 GO 跳转效果

现在越来越多的博客采用了外链跳转页面,据说可以防止外链影响自己 WordPress 博客的权重,导致搜索引擎降权。今天老俍就给大家分享一款漂亮的 WordPress 跳转 GO 样式,并且支持响应式布局。

WordPress 外链跳转样式 WordPress 外链跳转代码

将以下代码保存为 go.php 并上传到 WordPress 的根目录(与 wp-admin文件夹同级)。并自行替换需要修改的信息。

<?phpif(strlen($_SERVER['REQUEST_URI']) > 255 ||strpos($_SERVER['REQUEST_URI'], "eval(") ||strpos($_SERVER['REQUEST_URI'], "base64")) {@header("HTTP/1.1 414 Request-URI Too Long");@header("Status: 414 Request-URI Too Long");@header("Connection: Close");@exit;}//通过 QUERY_STRING 取得完整的传入数据,然后取得 url=之后的所有值,兼容性更好$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);//数据处理if(!empty($t_url)) {//判断取值是否加密if ($t_url == base64_encode(base64_decode($t_url))) {$t_url = base64_decode($t_url);}//对取值进行网址校验和判断preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$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 = 'http://'.$_SERVER['HTTP_HOST'];$title='参数错误,正在返回首页...';}}} else {$title = '参数缺失,正在返回首页...';$url = 'http://'.$_SERVER['HTTP_HOST'];}?><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"><meta name="robots" content="noindex, nofollow" /><noscript><meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"></noscript><script>function link_jump(){//禁止其他网站使用我们的跳转页面var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");if (!MyHOST.test(document.referrer)) {location.href="http://" + MyHOST;}}//延时 2S 跳转,可自行修改延时时间setTimeout(link_jump, 1000);//延时 50S 关闭跳转页面,用于文件下载后不会关闭跳转页的问题setTimeout(function(){window.opener=null;window.close();}, 50000);</script><title><?php echo $title;?></title><style>body{margin:0;padding:0 30px;background:#fff;font-size:12px}img{border:none}a{text-decoration:none;cursor:pointer;outline:0}a:hover{text-decoration:underline}a,a:link,a:visited{color:#1e5494}a.btn_blue:focus{border-color:#93d4fc;box-shadow:0 0 5px #60caff}a.btn_blue{display:inline-block;padding:6px 25px;margin:0;font-size:14px;font-weight:700;text-align:center;border-radius:3px;border:1px solid #0d659b;color:#fff;color:#fff!important;background-color:#238aca;background:-moz-linear-gradient(top,#238aca,#0074bc);background:-webkit-linear-gradient(top,#238aca,#0074bc);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#238aca', endColorstr='#0074bc');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#238aca', endColorstr='#0074bc')"}a.btn_blue:hover{text-decoration:none;background-color:#238aca;background:-moz-linear-gradient(top,#2a96d8,#0169a9);background:-webkit-linear-gradient(top,#2a96d8,#0169a9);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#2a96d8', endColorstr='#0169a9');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#2a96d8', endColorstr='#0169a9')"}a.btn_blue:active{background-color:#238aca;background:-moz-linear-gradient(top,#0074bc,#238aca);background:-webkit-linear-gradient(top,#0074bc,#238aca);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0074bc', endColorstr='#238aca');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#0074bc', endColorstr='#238aca')";outline:0}.remind_block{overflow:hidden}.remind_block .remind_content{overflow:hidden}.remind_block .remind_title{margin-bottom:10px;padding-top:3px;font-weight:700;font-size:20px;font-family:"Microsoft YaHei","lucida Grande",Verdana}.remind_block .remind_detail{line-height:1.5;font-size:16px;color:#535353}.warning .remind_title{color:#16a085}.container{max-width:640px;margin:0 auto;padding-top:25px}.header{margin-bottom:5px}.footer{margin-top:18px;text-align:center;color:#a0a0a0;font-size:10px}.content{border:1px solid #bbb;box-shadow:0 0 3px #d4d4d4}.c-container{padding:30px}.c-footer{padding:10px 15px;background:#f1f1f1;border-top:1px solid #bbb;overflow:hidden}.c-footer-a1,.c-footer-a2{float:left}.c-footer-a2{margin:8px 0 0 15px}.safety-url{margin-bottom:15px;padding-bottom:15px;border-bottom:1px solid #dfdfdf;word-wrap:break-word;word-break:break-all}</style></head><body><div class="container"><div class="header"><img width="270" height="80" src=""></div><div class="content"><div class="c-container warning"><div id="remind_block" class="remind_block" style="height: 260px;"><div class="remind_content"><div class="remind_title">您将要访问:</div><div class="remind_detail"><div class="safety-url"><?php echo $url;?></div><span style="color:#CC0000;font-weight:800;">访问提示:</span><br/>您即将离开「俍注」,该网页可能包含未知的安全隐患,请注意您的账号和财产安全。</div></div></div></div></div><div class="c-footer"><a href="<?php echo $url;?>" rel="nofollow" class="c-footer-a1 btn_blue">继续访问</a><a class="c-footer-a2" href="/" rel="nofollow">返回主页</a></div></div><div class="footer">Copyright ? 俍注</div></body></html>

在 functions.php 任意位置加入如下代码,即可对所有外链实现 GO 跳转效果。

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;}

友情提示:如果博客主题更新了 functions.php 文件需要重新上传第二段代码。

免插件实现WordPress外链go跳转

为了假装在做SEO,避免权重分散,今天就给大家分享一个免插件实现WordPress外链go跳转,非常简单。

步骤一:

在网站根目录新建一个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;?>';"><title><?php echo $title;?></title><style>body {background:#000}.loading { -webkit-animation:fadein 2s; -moz-animation:fadein 2s; -o-animation:fadein 2s; animation:fadein 2s}@-moz-keyframes fadein {from {opacity:0}to {opacity:1}}@-webkit-keyframes fadein {from {opacity:0}to {opacity:1}}@-o-keyframes fadein {from {opacity:0}to {opacity:1}}@keyframes fadein {from {opacity:0}to {opacity:1}}.spinner-wrapper { position:absolute; top:0; left:0; z-index:300; height:100%; min-width:100%; min-height:100%; background:#3498db}.spinner-text { position:absolute; top:50%; left:50%; margin-left:-200px; margin-top: 2px; color:#fff; letter-spacing:1px; font-weight:700; font-size:36px; font-family:Arial}.spinner { position:absolute; top:50%; left:50%; display:block; margin-left:-270px; width:1px; height:1px; border:25px solid rgba(100,100,100,0.2); -webkit-border-radius:50px; -moz-border-radius:50px; border-radius:50px; border-left-color:transparent; border-right-color:transparent; -webkit-animation:spin 1.5s infinite; -moz-animation:spin 1.5s infinite; animation:spin 1.5s infinite}@-webkit-keyframes spin {0%,100% {-webkit-transform:rotate(0deg) scale(1)}50% {-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin {0%,100% {-moz-transform:rotate(0deg) scale(1)}50% {-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin {0%,100% {-o-transform:rotate(0deg) scale(1)}50% {-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin {0%,100% {transform:rotate(0deg) scale(1)}50% {transform:rotate(720deg) scale(0.6)}}</style></head><body><div class="loading"> <div class="spinner-wrapper"> <span class="spinner-text">页面正在安全跳转中,请稍候</span> <span class="spinner"></span> </div></div></body></html>

步骤二:

将下面代码加到主题的functions.php文件中:

//给外部链接加上go跳转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;}