无需插件为WordPress的文章外链转内链且进行Base64加密

此教程来自于pc6a,它可以把自动外部链转换成“你的网址/ go /”。非常方便,而且是php自动转换的,不存储数据,不需要占用服务器的空间。绝大部分代码都是直接引用。小白的教程更适合跟我一样的纯小白使用。

一,添加加密代码

首先打开主题文件夹下functions.php文件,按需添加以下代码

1,文章外链转内链:

//文章外部链伪伪静态版
add_filter ('the_content' ,'link_jump' ,999 ); 函数link_jump ($ content ){ 
preg_match_all ('/<a ( .*? ) href=" ( .*?)" ( .*?)>/' ,$ content ,$ matches ); if ($ matches ){ foreach ($ matches [ 2 ] as $ val ){ if (strpos ($ val ,'://' )!== false && strpos ($ val


 
     ,HOME_URL ())===假&& !preg_match ('/\. ( jpg|jepg|png|ico|bmp|gif|tiff )/ i' ,$ val )&& !preg_match ('/(ed2k | thunder | Flashget | flashget | qqdl):\ / \ // i' ,$ val )){ 
    $ content = str_replace (“ href = \” $ val \“” ,“ href = \” “ HOME_URL ()。”/去/“ 。BASE64_ENCODE ($ VAL )。”\“相对= \” nofollow的\ “目标= \ ”_空白\“” ,$ content ); } } }     
    


返回$ content ; }

2,评论外链转内链:

//评论者链接重置函数commentauthor ($ comment_ID = 0 ){ 
$ url     = get_comment_author_url ($ comment_ID ); 
$ author = get_comment_author ($ comment_ID ); if (空($ url )|| 'http://' == $ url ){ 
echo $ author ; } else { if (!preg_match (home_url (),$ url )){
  
     
  
  
    回声“ <a href ='” 。home_url ()。“ / go /” 。base64_encode ($ url )。“'rel ='nofollow'target ='_ blank'class ='url'> $ author </a>” ;} else { 
    echo “ <a href='$url' target='_blank' class='url'> $ author </a>” ; } } }
  

   

二,创建go缩短文件

在网站根目录创建go.html文件,在文件中写入以下代码:

<html> <head> <meta http-equiv = “ Content-Type” content = “ text / html; charset = UTF-8” > <meta name = “ robots” content = “ noindex,nofollow” /> <script> // base64加密解密函数var base64EncodeChars = “ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /” ; var base64DecodeChars =新数组(-1 ,-1 ,-1 ,-1 ,-1 ,

  
   


 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,62 , - 1 , - 1 , - 1 ,63 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 ,61 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);function base64encode(str){var out,i,len;var c1,c2,c3;len=str.length;i=0;out="";while(i<len){c1=str.charCodeAt(i++)&255;if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt((c1&3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt((c2&15)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=base64EncodeChars.charAt(c1>>2);out+=base64EncodeChars.charAt(((c1&3)<<4)|((c2&240)>>4));out+=base64EncodeChars.charAt(((c2&15)<<2)|((c3&192)>>6));out+=base64EncodeChars.charAt(c3&63)}return out}function base64decode(str){var c1,c2,c3,c4;var i,len,out;len=str.length;i=0;out="";while(i<len){do{c1=base64DecodeChars[str.charCodeAt(i++)&255]}while(i<len&&c1==-1);if(c1==-1){break}do{c2=base64DecodeChars[str.charCodeAt(i++)&255]}while(i<len&&c2==-1);if(c2==-1){break}out+=String.fromCharCode((c1<<2)|((c2&48)>>4));do{c3=str.charCodeAt(i++)&255;if(c3==61){return out}c3=base64DecodeChars[c3]}while(i<len&&c3==-1);if(c3==-1){break}out+=String.fromCharCode(((c2&15)<<4)|((c3&60)>>2));do{c4=str.charCodeAt(i++)&255;if(c4==61){return out}c4=base64DecodeChars[c4]}while(i<len&&c4==-1);if(c4==-1){break}out+=String.fromCharCode(((c3&3)<<6)|c4)}return out}function utf16to8(str){var out,i,len,c;out="";len=str.length;for(i=0;i<len;i++){c=str.charCodeAt(i);if((c>=1)&&(c<=127)){out+=str.charAt(i)}else{if(c>2047){out+=String.fromCharCode(224|((c>>12)&15));out+=String.fromCharCode(128|((c>>6)&63));out+=String.fromCharCode(128|((c>>0)&63))}else{out+=String.fromCharCode(192|((c>>6)&31));out+=String.fromCharCode(128|((c>>0)&63))}}}return out}function utf8to16(str){var out,i,len,c;var char2,char3;out="";len=str.length;i=0;while(i<len){c=str.charCodeAt(i++);switch(c>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:out+=str.charAt(i-1);break;case 12:case 13:char2=str.charCodeAt(i++);out+=String.fromCharCode(((c&31)<<6)|(char2&63));break;case 14:char2=str.charCodeAt(i++);char3=str.charCodeAt(i++);out+=String.fromCharCode(((c&15)<<12)|((char2&63)<<6)|((char3&63)<<0));break}}return out}function doit(){var f=document.f;f.output.value=base64encode(utf16to8(f.source.value));f.decode.value=utf8to16(base64decode (˚F 。输出。值))}; //获取请求参数,支持伪静态函数GetQueryString (name ){ var reg = new RegExp (“(^ |&)” + name + “ =(。*)$” ); var r = window 。位置。搜索。substr (1 )。比赛(reg ); 如果(r != null ){

 

   
 
   
     返回  unescape (r [ 2 ]); } else {返回窗口。位置。路径名。替换('/ go /' ,'' ); //注意代码中的/ go /和替换地址/ go /保持一致,请记得自行修改!} } var jump_url = GetQueryString (“ url” ); //如果假设的是基础加密数据,则进行解密处理if (jump_url == base64encode (base64decode (jump_url ))){ 
jump_url =
   
      
 

 

 base64decode (jump_url ); } // url简单正则var UrlReg = “ ^((http | https | thunder | qqdl | ed2k | Flashget | qbrowser | ftp | rtsp | mms)://)” ; //自定义一些重新压缩字符串,请根据实际需求自行发挥if (jump_url == “ kpapt” ){ var jump_url = “ https://www.kpapt.com/” ; } if (jump_url == “ baidu” ){ var jump_url = “ https://www.baidu.com/” ; } //网址验证if (jump_url ==


   

 


 



 空|| jump_url 。toString ()。长度< 1 || !jump_url 。match (UrlReg )){
文档。title = '参数错误,正在返回首页...' ; 
jump_url =位置。起源; } //延时执行跳转
的setTimeout (函数link_jump (){ //非本站域名不允许使用此跳转页面,请自行修改www.kpapt.com为自己的域名变种MYHOST =新正则表达式(“WWW。 kpapt.com”     



   

    ); 如果(!MYHOST 。测试(文件。引荐)){
    位置。href = “ http://” + MyHOST ; 回报; }
位置。href = jump_url ; },1000 ); 
的setTimeout (函数(){窗口。开瓶器=空;窗口。关闭();},50000 ); </ script> <title>
     
    

  

页面加载中,请稍候... </ title> <style type = “ text / css” >
正文{背景:
 #555} .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淡入{from {opacity:0}到{opacity:1}} @-o-keyframes淡入{from {opacity:0}到{opacity:1}} @ keyframes淡入{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:rgba(255,255,255,0.93)}。spinner-text {position:absolute; top:45%; left:50%; margin-left:-100px; margin-top:2px; color:#000; letter-spacing:1px; font-size:20px; font-family:Arial} .spinner {position:absolute; top:45%; left:50%; display:block; margin-left:-160px; width:1px;高度:1像素;边框:20像素实心rgba(255,0,0,1);-webkit-边框半径:50像素; -moz边框半径:50像素;边框半径:50像素;边框左侧颜色:透明; border-right-color:transparent;-webkit-animation:旋转1.5s无限; -moz-animation:旋转1.5s无限; animation:旋转1.5s无限} @-webkit-关键帧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-关键帧旋转{0%,100%{-o-transform:rotate(0deg)scale(1)} 50%{-o- transform:rotate(720deg)比例尺(0.6)}} @关键帧旋转{0%,100%{transform:rotate(0deg)比例尺(1)} 50%{transform:rotate(720deg)比例尺(0.6)}}旋转(720度)缩放比例(0.6)}}@-o-关键帧旋转{0%,100%{-o-transform:rotate(0deg)缩放比例(1)} 50%{-o-transform:rotate(720deg)比例缩放(0.6)}} @关键帧旋转{0%,100%{transform:rotate(0deg)标度(1)} 50%{transform:rotate(720deg)标度(0.6)}}旋转(720度)缩放比例(0.6)}}@-o-关键帧旋转{0%,100%{-o-transform:rotate(0deg)缩放比例(1)} 50%{-o-transform:rotate(720deg)比例缩放(0.6)}} @关键帧旋转{0%,100%{transform:rotate(0deg)标度(1)} 50%{transform:rotate(720deg)标度(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>


 
 
 
 



三,修改伪静态

如果是宝塔直接在网站-设置-伪静态,最后一行添加下方代码即可

NGINX代码:

改写^ /去/ (。*)$ /去。HTML ?url = $ 1 last ;

Apache代码:

重写规则^去/(.*)$ /去。HTML ?网址= $ 1 [ L ] 

四,其他须知





www.kpapt.com是小麦的域名,记得改成自己的;
/ go /中的go可以修改成自己喜欢的;
记得在robots.txt中排除/ go /;
WP教程

WordPress文章中的”&“被转义成“&amp ;“的解决方案

2020-11-4 18:08:04

WP教程

通过代码快速解决WordPress被群发大量英文评论的方法

2020-11-4 18:52:07

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧