- 資訊首頁(yè) > 互聯(lián)網(wǎng) > 經(jīng)驗分享 >
- 防權重流失防抄襲,WordPress博客文章正文外鏈無(wú)
我們知道做網(wǎng)站會(huì )想著(zhù)盡量增加內鏈,或外部網(wǎng)站鏈入自己的網(wǎng)頁(yè)鏈接,以提高蜘蛛抓取的幾率,防止網(wǎng)站權重的流失,當然作為測評站,經(jīng)常會(huì )分享各個(gè)IDC主機商促銷(xiāo)活動(dòng)及其產(chǎn)品購買(mǎi)鏈接,這個(gè)時(shí)候我們一方面我們不希望我們文章被其他測評站抄襲,更不能鏈出到過(guò)多外部鏈接。
幸運的是我們有一些方法實(shí)現文章正文外鏈轉內鏈,比如插件,不過(guò)本文老劉博客分享的是一直代碼方式無(wú)插件實(shí)現WordPress博客文章正文外鏈自動(dòng)轉內鏈教程,以防網(wǎng)站權重流失防文章被抄襲。
以老劉博客DUX主題為例:
1,自動(dòng)給文章的外部鏈接添加nofollow屬性,將如下代碼加到DUX主題文件夾下function-theme.php文件里:
/*
*自動(dòng)給文章的外部鏈接添加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內鏈,在網(wǎng)站根目錄下創(chuàng )建名為”go“的文件夾,在go文件夾下創(chuàng )建index.php文件,并在文件里寫(xiě)入如下代碼:
<?php
$url = $_GET['url'];
$a = '';
if( $a==$url ) {
$b = "https://www.laoliublog.cn/";
// echo 'true';
} else {
$b = $url;
$b = base64_decode($b);
}
//Template Name:鏈接跳轉(有過(guò)度)
?>
<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/”中網(wǎng)址鏈接替換成自己的即可。
3,以上代碼增加了跳轉美化效果,代碼中已經(jīng)用base64將源鏈接加密,并且加上了nofollow,但恐怕蜘蛛還是能爬行,在Robots禁止所有蜘蛛爬行/go?url目錄!
Disallow: /go/
Disallow: /go?url
通過(guò)以上步驟,就可以實(shí)現WordPress博客文章正文外鏈無(wú)插件代碼自動(dòng)轉內鏈了~
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站