wordpress网站外链自动转内链代码

1,自动给文章的外链转内链并添加nofollow属性,将如下代码加到wordpress主题文件夹下function.php文件里:

/*
*自动给文章的外部链接添加nofollow属性
*/ 
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
 preg_match_all('/href="(http.*?)"/',$content,$matches);
 if($matches){
 foreach($matches[1] as $val){
 if( strpos($val,home_url())===false ) 
 $content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val). "\"",$content);
 }
 }
 return $content;
}

2,跳go内链,在网站根目录下创建名为”go“的文件夹,在go文件夹下创建index.php文件,并在文件里写入如下代码:

<?php 
$url = $_GET['url'];
$a = '';
if( $a==$url ) {
 $b = "https://www.网站.com/";
// echo 'true';
} else {
 $b = $url;
 $b = base64_decode($b);
}
//Template Name:链接跳转(有过度)
?>
 
<html>
<head>
<meta charset=utf-8 />
<meta name="robots" content="nofollow">
<meta http-equiv="refresh" content="0.1;url=<?php echo $b; ?>">
<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:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:41.5%;left:47%;margin:16px 0 0 35px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:9px;font-family:Arial}.spinner{position:absolute;top:40%;left:45%;display:block;margin:0;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>

将$b = “https://www.网站.com/”中网址链接替换成自己的即可。

3,以上代码增加了跳转美化效果,代码中已经用base64将源链接加密,并且加上了nofollow,但恐怕蜘蛛还是能爬行,在Robots禁止所有蜘蛛爬行/go?url目录!

Disallow: /go/
Disallow: /go?url

通过以上步骤,就可以实现WordPress博客文章正文外链无插件代码自动转内链了~

版权所有,作者:老钟,如若转载,请注明出处:https://www.laoz.net/1193.html

赞 (1)
老钟
上一篇 2021 年 10 月 25 日 下午 4:33
下一篇 2022 年 04 月 28 日 下午 3:05

相关推荐

  • Justnews主题破解版开心版源码下载6.14.1

    JustNews主题专为博客、自媒体、资讯类的网站设计开发,自适应兼容手机、平板设备,支持前端用户中心,可以前端发布/投稿文章,同时主题支持专题功能,可以添加文章专题。 JustNews主题6.14.1为官方原版,来自WPCOM…

    2023 年 07 月 22 日
  • 本地wamp实现伪静态

    来分享一下本地wamp实现伪静态: 第一步:找到Apache安装目录下httpd.conf这个文件,搜索找到,“LoadModule rewrite_module modules/mod_rewrite.so”,找到这一行,去掉前面的“#”; 第二步:找到“AllowOverride Non…

    wordpress建站 2012 年 03 月 21 日
  • 解决Waiting (TTFB)网页加载时间过长的问题

    有时候wordpress网页加载时间需要几秒,通过浏览器开发者工具发现Waiting (TTFB)的这个, 打开wp-config.php文件,把localhost修改为127.0.0.1,瞬间加载时间可以大大减少 loclahost和127.0.0.1的区别 127.0.0.1无…

    wordpress建站 2022 年 11 月 08 日
  • LNMP安装教程(自动安装Nginx、PHP、MySQL、phpMyAdmin、Zend)[转]

    1,用putty登陆你的vps. 2,下载LNMP一键安装包:wget -c http://soft.vpser.net/lnmp/lnmp0.7-full.tar.gz 3,解压一键安装包: tar zxvf lnmp0.7-full.tar.gz 4、CentOS下安装步骤 执行命令:cd lnmp0.7-full/ 然后…

    wordpress建站 2011 年 08 月 08 日
  • burst年末优惠码 84优惠码,20% off

    年底了burst有开始出优惠码了,这次是20% off,适用于所有的vps 有效期: ~ 至2012.12.31 时间有限哦,如果有需要代购vps ,请联系~~优惠~

    wordpress建站 2011 年 12 月 13 日
  • 自动匹配符号并添加12345数字标识符的PHP代码

    主要是符合当前百度搜索的需求,把内容进行数字符号的添加,分点来叙述答案内容,具体看代码: <?php header("Content-type:text/html; charset=utf-8"); $text = $_GET['mtx']; $arr = multiexplode(array("[",…

    wordpress建站 2022 年 10 月 12 日
  • 只有坚持更新的网站才能被搜索引擎喜爱并且乐于收录

    回想一下老钟的建站历程,从2007年高中时代,我就开始接触到建站,当时还不清楚如何申请域名,不清楚什么是空间。 当时建的站点是手机站点,因为那时候智能手机时代准备开始爆发,记得当时UC浏览器还是刚开始发展的…

    2016 年 05 月 09 日
  • mysql 新建用户,分配权限 ,解决 #1045 无法登录 问题

    先说一下我的情况,我的vps安装了lnmp 7.0,然后用phpmyadmin分配用权限 用root用户登录phpmyadmin,然后点击权限---->添加新用户---->分配权限 按照下图操作,圈有红圈的就注意下 记得在服务器: flush priv…

    2011 年 07 月 31 日
  • lnmp 等 状态管理

    状态管理 LNMP状态管理: /root/lnmp {start|stop|reload|restart|kill|status} Nginx状态管理:/etc/init.d/nginx {start|stop|reload|restart} PHP-FPM状态管理:/etc/init.d/php-fpm {start|stop|quit|restart|r…

    wordpress建站 2011 年 08 月 07 日
  • 入手了新玉米 laoz.net

    一直没发现有什么好一点的玉米,所以自己的博客就拿了一个二级域名去放置! 已经有很长的一段时间了,今天突发奇想,试试有没有什么新的玉米可以使用,突然发现了laoz.net 冲动的性格一时忍不住,下单付款,就这么…

    wordpress建站 2014 年 04 月 14 日