Original link: https://oneinf.com/tech/net/wp/8969.html
Now more and more blogs use external links to jump pages, which is said to prevent external links from affecting the weight of their own WordPress blogs and causing search engines to drop their weight. Today , I will share with you a beautiful WordPress jump GO style, which supports responsive layout.
WordPress External Link Jump Style
WordPress external link jump code
Save the following code as go.php and upload it to the root directory of WordPress (same level as the wp-admin folder). And replace the information that needs to be modified by yourself.
<?php if(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; } //Get the complete incoming data through QUERY_STRING, and then get all the values after url=, better compatibility $t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER[ "QUERY_STRING"]); //Data processing if(!empty($t_url)) { //Judge whether the value is encrypted if ($t_url == base64_encode(base64_decode($t_url))) { $t_url = base64_decode($t_url); } //Url verification and judgment on the value preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches); if ($matches) { $url=$t_url; $title='The page is loading, please wait...'; } else { preg_match('/\./i', $t_url, $matche); if ($matches) { $url='http://'.$t_url; $title='The page is loading, please wait...'; } else { $url = 'http://'.$_SERVER['HTTP_HOST']; $title='Parameter error, returning to home page...'; } } } else { $title = 'The parameter is missing, returning to the home page...'; $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() { //Forbid other websites to use our jump page var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>"); if (!MyHOST.test(document.referrer)) { location.href="http://" + MyHOST; } } //Delay 2S jump, you can modify the delay time setTimeout(link_jump, 1000); //Delay 50S to close the jump page, for the problem that the jump page will not be closed after the file is downloaded 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.gradie nt(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-s ize: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="https://oneinf.com/wp-content/uploads/2022/09/logo_2.0.png"> </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"> You will visit: </div> <div class="remind_detail"> <div class="safety-url"> <?php echo $url;?> </div> <span style="color:#CC0000;font-weight:800;">Access prompt:</span><br/>You are about to leave "Note", this webpage may contain unknown security risks, please pay attention to your Account and property security. </div> </div> </div> </div> </div> <div class="c-footer"> <a href="<?php echo $url;?>" rel="nofollow" class="c-footer-a1 btn_blue">Continue to visit</a><a class="c-footer-a2" href= "/" rel="nofollow">Back to home page</a> </div> </div> <div class="footer">Copyright © Note</div> </body> </html>
Add the following code anywhere in functions.php to realize the GO jump effect for all external links.
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; }
Friendly reminder: If the functions.php file is updated in the blog theme, the second code needs to be uploaded again.
This article is transferred from: https://oneinf.com/tech/net/wp/8969.html
This site is only for collection, and the copyright belongs to the original author.