咱知道,凡有一点 SEO 基础的筒子都明白一个道理,即:绝不能容忍自己的权重流失!特别是指向那些不必要的站点。所以此前,本屌把所有的出站链接都干掉了,包括版权信息,可谓干尽所有恶俗事情(最先的 Youth Daily,非本博)。实现方法如下:首先,在你当前使用的主题的 functions.php
中加入以下代码:
// https://www.shephe.com/ 外链跳转
add_filter('the_content','go_url',999);
function go_url($content){
preg_match_all(‘/href="(.*?)"/’请去掉这几个汉字并把这对单引号修改为半角,$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false&&strpos($val,"javascript:void(0)")===false )
$content=str_replace("href=\"$val\"", "rel=\"nofollow\" target=\"_blank\" href=\"" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val). "\"",$content);
}
}
return $content;
}
注意修改相应部分。然后在网站根目录下新建个 go 的文件夹,在其中写个 index.php 的文件,内容如下(请保存为UTF-8):
<?php $url = $_GET['url']; $url = base64_decode($url); ?>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0.1;url=</?php echo $url; ?>">
跳转页
至此基本上大功告成了,亲们可以 点击这里(weibo.com/finle) 试试效果怎么样…至于这样做是否对 SEO 有利/有弊,还请各位明白人指点指点。另外:中间页大家可发挥想象,想怎么写就怎么写吧,这是 @张戈 的样式,觉得还不错,遂更新了下:
<?php
$url = $_GET['url'];
$url = base64_decode($url);
?>
<html>
<head>
<meta charset=utf-8 />
<meta name="robots" content="nofollow">
<meta http-equiv="refresh" content="0.1;url=<?php echo $url; ?>">
<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>
补充一点。尽管代码中已经用 base64 将源链接加密,并且加上了 nofollow,但恐怕蜘蛛还是能爬行,所以干脆一不做二不休,在 Robot s 禁止所有蜘蛛爬行 /go?url 目录吧!
找代码搞不定,还是直接用插件方便。