老刘博客laoliublog.cn
建站技术分享站点!
justhost
aws
cdncloud
ptgidc
huocloud
recloud
hncloud

防权重流失防抄袭,WordPress博客文章正文外链无插件代码实现自动转内链教程

racknerd

我们知道做网站会想着尽量增加内链,或外部网站链入自己的网页链接,以提高蜘蛛抓取的几率,防止网站权重的流失,当然作为测评站,经常会分享各个IDC主机商促销活动及其产品购买链接,这个时候我们一方面我们不希望我们文章被其他测评站抄袭,更不能链出到过多外部链接。

幸运的是我们有一些方法实现文章正文外链转内链,比如插件,不过本文老刘博客分享的是一直代码方式无插件实现WordPress博客文章正文外链自动转内链教程,以防网站权重流失防文章被抄袭。

防权重流失防抄袭,WordPress博客文章正文外链无插件代码实现自动转内链教程

老刘博客DUX主题为例:

1,自动给文章的外部链接添加nofollow属性,将如下代码加到DUX主题文件夹下function-theme.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.laoliublog.cn/";
// 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.laoliublog.cn/”中网址链接替换成自己的即可。

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

Disallow: /go/
Disallow: /go?url

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

关于 老刘博客

本站宗旨是为方便站长、科研及外贸人员,请勿用于其它非法用途!站内所有内容及资源,均来自网络。本站自身不提供任何资源的储存及下载,若无意侵犯到您的权利,请及时与我们联系。

未经允许不得转载:老刘博客 » 防权重流失防抄袭,WordPress博客文章正文外链无插件代码实现自动转内链教程
在线客服
在线客服
QQ客服