• 欢迎访问老K博客,关注网络营销技术,分享网络营销精神!欢迎加入我们
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏老K博客吧

WordPress外链新窗口打开并使用php页面go跳转

WordPress教程 老K 9个月前 (11-20) 572次浏览 已收录 0个评论

昨天,使用了php页面开启了外链go跳转,以便小伙伴有充足的时间考虑是否访问第三方页面,毕竟有时候外链地址是会改变的,或者有些小伙伴不小心按到。所以,这次的go跳转设置了5秒钟的缓冲时间,效果如下:

WordPress外链新窗口打开并使用php页面go跳转

怎么样?跳转页面还是挺好看的吧!

go.php页面代码

首先在网站根目录创建一个名字为 go 的文件夹,并在该文件夹中创建 index.php 文件。

<span class="pun"><?</span><span class="pln">php
</span><span class="com">/**
* WordPress外链<a href="http://www.laoking.net/tag/go%e8%b7%b3%e8%bd%ac" title="查看更多关于go跳转的文章" target="_blank">go跳转</a>页面 - 
* @copyright (c) Emlog All Rights Reserved
*/</span>
<span class="com">//自定义跳转地址</span><span class="pln">
$cars </span><span class="pun">=</span><span class="pln"> array</span><span class="pun">(</span><span class="pln">
array</span><span class="pun">(</span><span class="str">"qcloud"</span><span class="pun">,</span><span class="str">'http://www.qcloud.com/redirect.php?redirect=1001&cps_key=8558139aea55e95d71f488081ba44577'</span><span class="pun">),</span><span class="pln">
array</span><span class="pun">(</span><span class="str">"upyun"</span><span class="pun">,</span><span class="str">'https://www.upyun.com/league'</span><span class="pun">),</span><span class="pln">
array</span><span class="pun">(</span><span class="str">"trustutn"</span><span class="pun">,</span><span class="str">'http://c.trustutn.org/s/aeink.com'</span><span class="pun">),</span><span class="pln">
array</span><span class="pun">(</span><span class="str">"gfvps"</span><span class="pun">,</span><span class="str">'https://www.gfvps.cn/page.aspx?c=referral&u=9023'</span><span class="pun">),</span><span class="pln">
array</span><span class="pun">(</span><span class="str">"360scan"</span><span class="pun">,</span><span class="str">'http://webscan.360.cn/index/checkwebsite/url/www.aeink.com'</span><span class="pun">)</span>
<span class="pun">);</span>

<span class="kwd">if</span><span class="pun">(</span><span class="pln">strlen</span><span class="pun">(</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">'REQUEST_URI'</span><span class="pun">])</span> <span class="pun">></span> <span class="lit">384</span> <span class="pun">||</span><span class="pln"> strpos</span><span class="pun">(</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">'REQUEST_URI'</span><span class="pun">],</span> <span class="str">"eval("</span><span class="pun">)</span> <span class="pun">||</span><span class="pln"> strpos</span><span class="pun">(</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">'REQUEST_URI'</span><span class="pun">],</span> <span class="str">"base64"</span><span class="pun">))</span> <span class="pun">{</span>
<span class="lit">@header</span><span class="pun">(</span><span class="str">"HTTP/1.1 414 Request-URI Too Long"</span><span class="pun">);</span>
<span class="lit">@header</span><span class="pun">(</span><span class="str">"Status: 414 Request-URI Too Long"</span><span class="pun">);</span>
<span class="lit">@header</span><span class="pun">(</span><span class="str">"Connection: Close"</span><span class="pun">);</span>
<span class="lit">@exit</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="com">//通过QUERY_STRING取得完整的传入数据,然后取得url=之后的所有值,兼容性更好</span><span class="pln">
$t_url </span><span class="pun">=</span><span class="pln"> htmlspecialchars</span><span class="pun">(</span><span class="pln">preg_replace</span><span class="pun">(</span><span class="str">'/^url=(.*)$/i'</span><span class="pun">,</span><span class="str">'$1'</span><span class="pun">,</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">"QUERY_STRING"</span><span class="pun">]));</span>

<span class="com">//此处可以自定义一些特别的外链,不需要可以删除以下5行</span>
<span class="kwd">foreach</span><span class="pun">(</span><span class="pln">$cars </span><span class="kwd">as</span><span class="pln"> $k</span><span class="pun">=></span><span class="pln">$val</span><span class="pun">){</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$t_url</span><span class="pun">==</span><span class="pln">$val</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]</span> <span class="pun">)</span> <span class="pun">{</span><span class="pln">
$t_url </span><span class="pun">=</span><span class="pln"> $val</span><span class="pun">[</span><span class="lit">1</span><span class="pun">];</span><span class="pln">
$t_vip </span><span class="pun">=</span> <span class="lit">1</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">}</span>

<span class="com">//数据处理</span>
<span class="kwd">if</span><span class="pun">(!</span><span class="pln">empty</span><span class="pun">(</span><span class="pln">$t_url</span><span class="pun">))</span> <span class="pun">{</span>
<span class="com">//判断取值是否加密</span>
<span class="kwd">if</span> <span class="pun">(</span><span class="pln">$t_url </span><span class="pun">==</span><span class="pln"> base64_encode</span><span class="pun">(</span><span class="pln">base64_decode</span><span class="pun">(</span><span class="pln">$t_url</span><span class="pun">)))</span> <span class="pun">{</span><span class="pln">
$t_url </span><span class="pun">=</span><span class="pln"> base64_decode</span><span class="pun">(</span><span class="pln">$t_url</span><span class="pun">);</span>
<span class="pun">}</span>
<span class="com">//对取值进行网址校验和判断</span><span class="pln">
preg_match</span><span class="pun">(</span><span class="str">'/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i'</span><span class="pun">,</span><span class="pln">$t_url</span><span class="pun">,</span><span class="pln">$matches</span><span class="pun">);</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$matches</span><span class="pun">){</span><span class="pln">
$url</span><span class="pun">=</span><span class="pln">$t_url</span><span class="pun">;</span><span class="pln">
$title</span><span class="pun">=</span><span class="str">'页面加载中,请稍候...'</span><span class="pun">;</span>
<span class="pun">}</span> <span class="kwd">else</span> <span class="pun">{</span><span class="pln">
preg_match</span><span class="pun">(</span><span class="str">'/\./i'</span><span class="pun">,</span><span class="pln">$t_url</span><span class="pun">,</span><span class="pln">$matche</span><span class="pun">);</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$matche</span><span class="pun">){</span><span class="pln">
$url</span><span class="pun">=</span><span class="str">'http://'</span><span class="pun">.</span><span class="pln">$t_url</span><span class="pun">;</span><span class="pln">
$title</span><span class="pun">=</span><span class="str">'页面加载中,请稍候...'</span><span class="pun">;</span>
<span class="pun">}</span> <span class="kwd">else</span> <span class="pun">{</span><span class="pln">
$url </span><span class="pun">=</span> <span class="str">'http://'</span><span class="pun">.</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">'HTTP_HOST'</span><span class="pun">];</span><span class="pln">
$title</span><span class="pun">=</span><span class="str">'参数错误,正在返回首页...'</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">}</span>
<span class="pun">}</span> <span class="kwd">else</span> <span class="pun">{</span><span class="pln">
$title </span><span class="pun">=</span> <span class="str">'参数缺失,正在返回首页...'</span><span class="pun">;</span><span class="pln">
$url </span><span class="pun">=</span> <span class="str">'http://'</span><span class="pun">.</span><span class="pln">$_SERVER</span><span class="pun">[</span><span class="str">'HTTP_HOST'</span><span class="pun">];</span>
<span class="pun">}</span>
<span class="pun">?></span>
<span class="tag"><html></span>

<span class="tag"><head></span>
<span class="tag"><meta</span> <span class="atn">http-equiv</span><span class="pun">=</span><span class="atv">"Content-Type"</span> <span class="atn">content</span><span class="pun">=</span><span class="atv">"text/html; charset=UTF-8"</span><span class="tag">></span>
<span class="tag"><meta</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"viewport"</span> <span class="atn">content</span><span class="pun">=</span><span class="atv">"width=device-width"</span><span class="tag">></span>
<span class="tag"><meta</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"robots"</span> <span class="atn">content</span><span class="pun">=</span><span class="atv">"noindex, nofollow"</span> <span class="tag">/></span>
<span class="tag"><noscript></span><span class="pln"><meta http-equiv="refresh" content="1;url='</span><span class="pun"><?</span><span class="pln">php echo $url</span><span class="pun">;?></span><span class="pln">';"></span><span class="tag"></noscript></span>
<span class="tag"><meta</span> <span class="atn">charset</span><span class="pun">=</span><span class="atv">"UTF-8"</span><span class="tag">></span>
<span class="com"><!--[if IE 8]>
<style>
.ie8 .alert-circle,.ie8 .alert-footer{display:none}.ie8 .alert-box{padding-top:75px}.ie8 .alert-sec-text{top:45px}
</style>
<![endif]--></span>

<span class="tag"><title></span><span class="pun"><?</span><span class="pln">php echo $title</span><span class="pun">;?></span><span class="tag"></title></span>
<span class="tag"><style></span><span class="pln">
body</span><span class="pun">{</span><span class="pln">margin</span><span class="pun">:</span><span class="lit">0</span><span class="pun">;</span><span class="pln">padding</span><span class="pun">:</span><span class="lit">0</span><span class="pun">;</span><span class="pln">background</span><span class="pun">:</span><span class="com">#E6EAEB;font-family:Arial,'微软雅黑','宋体',sans-serif}.main{position:absolute;left:calc(50% - 200px);top:calc(50% - 13em)}.alert-box{display:none;position:relative;margin:auto;padding:180px 85px 22px;border-radius:10px 10px 0 0;background:#FFF;box-shadow:5px 9px 17px rgba(102,102,102,.75);width:286px;color:#FFF;text-align:center}.alert-box p{margin:0}.alert-circle{position:absolute;top:-50px;left:111px}.alert-sec-circle{stroke-dashoffset:0;stroke-dasharray:735;transition:stroke-dashoffset 1s linear}.alert-sec-text{position:absolute;top:11px;left:190px;width:76px;color:#000;font-size:68px}.alert-sec-unit{font-size:34px}.alert-body{margin:35px 0}.alert-head{color:#242424;font-size:28px}.alert-concent{margin:25px 0 14px;color:#7B7B7B;font-size:18px}.alert-concent p{line-height:27px}.alert-btn{display:block;border-radius:10px;background-color:#4AB0F7;height:55px;line-height:55px;width:286px;color:#FFF;font-size:20px;text-decoration:none;letter-spacing:2px}.alert-btn:hover{background-color:#6BC2FF}.alert-footer{margin:0 auto;height:42px;width:120px}.alert-footer-icon{float:left}.alert-footer-text{float:left;border-left:2px solid #EEE;padding:3px 0 0 5px;height:40px;color:#0B85CC;font-size:12px;text-align:left}.alert-footer-text p{color:#7A7A7A;font-size:22px;line-height:18px}</span>
<span class="tag"></style></span>
<span class="tag"></head></span>
<span class="tag"><body</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"ie8"</span> <span class="atn">style</span><span class="pun">=</span><span class="atv">""</span><span class="tag">></span>
<span class="tag"><div</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"main"</span><span class="tag">></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"js-alert-box"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-box"</span> <span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">display</span><span class="pun">:</span><span class="pln">block</span><span class="atv">"</span><span class="tag">></span>
<span class="tag"><svg</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-circle"</span> <span class="atn">width</span><span class="pun">=</span><span class="atv">"234"</span> <span class="atn">height</span><span class="pun">=</span><span class="atv">"234"</span><span class="tag">><circle</span> <span class="atn">cx</span><span class="pun">=</span><span class="atv">"117"</span> <span class="atn">cy</span><span class="pun">=</span><span class="atv">"117"</span> <span class="atn">r</span><span class="pun">=</span><span class="atv">"108"</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#FFF"</span> <span class="atn">stroke</span><span class="pun">=</span><span class="atv">"#43AEFA"</span> <span class="atn">stroke-width</span><span class="pun">=</span><span class="atv">"17"</span><span class="tag">></circle><circle</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"js-sec-circle"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-sec-circle"</span> <span class="atn">cx</span><span class="pun">=</span><span class="atv">"117"</span> <span class="atn">cy</span><span class="pun">=</span><span class="atv">"117"</span> <span class="atn">r</span><span class="pun">=</span><span class="atv">"108"</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"transparent"</span> <span class="atn">stroke</span><span class="pun">=</span><span class="atv">"#F4F1F1"</span> <span class="atn">stroke-width</span><span class="pun">=</span><span class="atv">"18"</span> <span class="atn">transform</span><span class="pun">=</span><span class="atv">"rotate(-90 117 117)"</span> <span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">stroke</span><span class="pun">-</span><span class="pln">dashoffset</span><span class="pun">:-</span><span class="lit">514px</span><span class="atv">"</span><span class="tag">></circle><text</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-sec-unit"</span> <span class="atn">x</span><span class="pun">=</span><span class="atv">"100"</span> <span class="atn">y</span><span class="pun">=</span><span class="atv">"172"</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#BDBDBD"</span><span class="tag">></span><span class="pln">秒</span><span class="tag"></text></svg></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"js-sec-text"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-sec-text"</span><span class="tag">></span><span class="pln">
3
</span><span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-body"</span><span class="tag">></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"js-alert-head"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-head"</span><span class="tag">></span>
<span class="pun"><?</span><span class="pln">php echo $title</span><span class="pun">;?></span>
<span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-concent"</span><span class="tag">></span>
<span class="tag"><p></span><span class="pln">一万年太久,只争朝夕</span><span class="tag"></p></span>
<span class="tag"></div></span><span class="pln">
<a id="js-alert-btn" class="alert-btn" href="</span><span class="pun"><?</span><span class="pln">php echo $url</span><span class="pun">;?></span><span class="pln">">立即前往</span><span class="tag"></a></span>
<span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-footer clearfix"</span><span class="tag">></span>
<span class="tag"><svg</span> <span class="atn">width</span><span class="pun">=</span><span class="atv">"46px"</span> <span class="atn">height</span><span class="pun">=</span><span class="atv">"42px"</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-footer-icon"</span><span class="tag">><circle</span> <span class="atn">fill-rule</span><span class="pun">=</span><span class="atv">"evenodd"</span> <span class="atn">clip-rule</span><span class="pun">=</span><span class="atv">"evenodd"</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#7B7B7B"</span> <span class="atn">stroke</span><span class="pun">=</span><span class="atv">"#DEDFE0"</span> <span class="atn">stroke-width</span><span class="pun">=</span><span class="atv">"2"</span> <span class="atn">stroke-miterlimit</span><span class="pun">=</span><span class="atv">"10"</span> <span class="atn">cx</span><span class="pun">=</span><span class="atv">"21.917"</span> <span class="atn">cy</span><span class="pun">=</span><span class="atv">"21.25"</span> <span class="atn">r</span><span class="pun">=</span><span class="atv">"17"</span><span class="tag">></circle><path</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#FFF"</span> <span class="atn">d</span><span class="pun">=</span><span class="atv">"M22.907,27.83h-1.98l0.3-2.92c-0.37-0.22-0.61-0.63-0.61-1.1c0-0.71,0.58-1.29,1.3-1.29s1.3,0.58,1.3,1.29 c0,0.47-0.24,0.88-0.61,1.1L22.907,27.83z M18.327,17.51c0-1.98,1.61-3.59,3.59-3.59s3.59,1.61,3.59,3.59v2.59h-7.18V17.51z M27.687,20.1v-2.59c0-3.18-2.59-5.76-5.77-5.76s-5.76,2.58-5.76,5.76v2.59h-1.24v10.65h14V20.1H27.687z"</span><span class="tag">></path><circle</span> <span class="atn">fill-rule</span><span class="pun">=</span><span class="atv">"evenodd"</span> <span class="atn">clip-rule</span><span class="pun">=</span><span class="atv">"evenodd"</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#FEFEFE"</span> <span class="atn">cx</span><span class="pun">=</span><span class="atv">"35.417"</span> <span class="atn">cy</span><span class="pun">=</span><span class="atv">"10.75"</span> <span class="atn">r</span><span class="pun">=</span><span class="atv">"6.5"</span><span class="tag">></circle><polygon</span> <span class="atn">fill</span><span class="pun">=</span><span class="atv">"#7B7B7B"</span> <span class="atn">stroke</span><span class="pun">=</span><span class="atv">"#7B7B7B"</span> <span class="atn">stroke-linecap</span><span class="pun">=</span><span class="atv">"round"</span> <span class="atn">stroke-linejoin</span><span class="pun">=</span><span class="atv">"round"</span> <span class="atn">stroke-miterlimit</span><span class="pun">=</span><span class="atv">"10"</span> <span class="atn">points</span><span class="pun">=</span><span class="atv">"35.417,12.16 32.797,9.03 31.917,10.07 35.417,14.25 42.917,5.29 42.037,4.25 "</span><span class="tag">></polygon></svg></span>
<span class="tag"><div</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"alert-footer-text"</span><span class="tag">></span>
<span class="tag"><p></span><span class="pln">secure</span><span class="tag"></p></span><span class="pln">安全加密
</span><span class="tag"></div></span>
<span class="tag"></div></span>
<span class="tag"></div></span>
<span class="tag"></div></span>
<span class="tag"><script</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="tag">></span>
<span class="kwd">function</span><span class="pln"> alertSet</span><span class="pun">(</span><span class="pln">e</span><span class="pun">)</span> <span class="pun">{</span><span class="pln">
document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"js-alert-box"</span><span class="pun">).</span><span class="pln">style</span><span class="pun">.</span><span class="pln">display </span><span class="pun">=</span> <span class="str">"block"</span><span class="pun">,</span><span class="pln"> document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"js-alert-head"</span><span class="pun">).</span><span class="pln">innerHTML </span><span class="pun">=</span><span class="pln"> e</span><span class="pun">;</span>
<span class="kwd">var</span><span class="pln"> t </span><span class="pun">=</span> <span class="lit">5</span><span class="pun">,</span><span class="pln">
n </span><span class="pun">=</span><span class="pln"> document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"js-sec-circle"</span><span class="pun">);</span><span class="pln">
document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"js-sec-text"</span><span class="pun">).</span><span class="pln">innerHTML </span><span class="pun">=</span><span class="pln"> t</span><span class="pun">,</span><span class="pln"> setInterval</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">()</span> <span class="pun">{</span>
<span class="com">//禁止其他网站调用此跳转</span>
<span class="com">//var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");</span>
<span class="com">//if (!MyHOST.test(document.referrer)) {</span>
<span class="com">// location.href="http://" + MyHOST;</span>
<span class="com">//}</span>
<span class="kwd">if</span> <span class="pun">(</span><span class="lit">0</span> <span class="pun">==</span><span class="pln"> t</span><span class="pun">)</span><span class="pln"> location</span><span class="pun">.</span><span class="pln">href </span><span class="pun">=</span> <span class="str">"<?php echo $url;?>"</span><span class="pun">;</span>
<span class="kwd">else</span> <span class="pun">{</span><span class="pln">
t </span><span class="pun">-=</span> <span class="lit">1</span><span class="pun">,</span><span class="pln"> document</span><span class="pun">.</span><span class="pln">getElementById</span><span class="pun">(</span><span class="str">"js-sec-text"</span><span class="pun">).</span><span class="pln">innerHTML </span><span class="pun">=</span><span class="pln"> t</span><span class="pun">;</span>
<span class="kwd">var</span><span class="pln"> e </span><span class="pun">=</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">round</span><span class="pun">(</span><span class="pln">t </span><span class="pun">/</span> <span class="lit">5</span> <span class="pun">*</span> <span class="lit">735</span><span class="pun">);</span><span class="pln">
n</span><span class="pun">.</span><span class="pln">style</span><span class="pun">.</span><span class="pln">strokeDashoffset </span><span class="pun">=</span><span class="pln"> e </span><span class="pun">-</span> <span class="lit">735</span>
<span class="pun">}</span>
<span class="pun">},</span> <span class="lit">970</span><span class="pun">)</span>
<span class="pun">}</span>
<span class="tag"></script></span>
<span class="tag"><script></span><span class="pln">alertSet</span><span class="pun">(</span><span class="str">"<?php echo $title;?>"</span><span class="pun">);</span><span class="tag"></script></span>
<span class="tag"></body></span>
<span class="tag"></html></span>

WordPress外链go跳转代码

这里可以 go文件夹 默认首页 index.php 为例,你也可以直接在网站根目录命名一个 go.php 或 goto.php 文件来编辑以上代码,随你自己喜好,但是下方代码也需要做相应的修改。下面的代码也就是缙哥哥现在使用的效果,代码如下,放在 WordPress 主题文件夹的 functions.php 文件内即可。

<span class="com">/**
* WordPress外链新窗口打开并使用php页面<a href="http://www.laoking.net/tag/go%e8%b7%b3%e8%bd%ac" title="查看更多关于go跳转的文章" target="_blank">go跳转</a>
* 
*/</span>
<span class="kwd">function</span><span class="pln"> the_content_nofollow</span><span class="pun">(</span><span class="pln">$content</span><span class="pun">){</span><span class="pln">
preg_match_all</span><span class="pun">(</span><span class="str">'/<a(.*?)href="(.*?)"(.*?)>/'</span><span class="pun">,</span><span class="pln">$content</span><span class="pun">,</span><span class="pln">$matches</span><span class="pun">);</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$matches</span><span class="pun">){</span>
<span class="kwd">foreach</span><span class="pun">(</span><span class="pln">$matches</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span> <span class="kwd">as</span><span class="pln"> $val</span><span class="pun">){</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">strpos</span><span class="pun">(</span><span class="pln">$val</span><span class="pun">,</span><span class="str">'://'</span><span class="pun">)!==</span><span class="kwd">false</span> <span class="pun">&&</span><span class="pln"> strpos</span><span class="pun">(</span><span class="pln">$val</span><span class="pun">,</span><span class="pln">home_url</span><span class="pun">())===</span><span class="kwd">false</span> <span class="pun">&&</span> <span class="pun">!</span><span class="pln">preg_match</span><span class="pun">(</span><span class="str">'/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i'</span><span class="pun">,</span><span class="pln">$val</span><span class="pun">)){</span><span class="pln">
$content</span><span class="pun">=</span><span class="pln">str_replace</span><span class="pun">(</span><span class="str">"href=\"$val\""</span><span class="pun">,</span> <span class="str">"href=\""</span><span class="pun">.</span><span class="pln">home_url</span><span class="pun">().</span><span class="str">"/go/?url=$val\" "</span><span class="pun">,</span><span class="pln">$content</span><span class="pun">);</span>
<span class="pun">}</span>
<span class="pun">}</span>
<span class="pun">}</span>
<span class="kwd">return</span><span class="pln"> $content</span><span class="pun">;</span>
<span class="pun">}</span><span class="pln">
add_filter</span><span class="pun">(</span><span class="str">'the_content'</span><span class="pun">,</span><span class="str">'the_content_nofollow'</span><span class="pun">,</span><span class="lit">999</span><span class="pun">);</span>

好了,go跳转就是这么简单。

 


老K博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:WordPress外链新窗口打开并使用php页面go跳转
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址