加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

WordPress 外链转内链的两种方法

发布时间:2020-12-14 14:34:21 所属栏目:wordpress 来源:网络整理
导读:首先,为什么要做内链转外链呢?用内链来跳转外链最起码也可以防止你网站权重流失,在这里给大家分享一段wordpress文章与页面外链转内链的代码,并且支持跳转页、加nofollow标签、加密原链接功能。另外你也可以使用插件来完成。 一、无插件 首先,在你当前使

首先,为什么要做内链转外链呢?用内链来跳转外链最起码也可以防止你网站权重流失,在这里给大家分享一段wordpress文章与页面外链转内链的代码,并且支持跳转页、加nofollow标签、加密原链接功能。另外你也可以使用插件来完成。

一、无插件

首先,在你当前使用主题的 functions.php 中加入以下代码

add_filter('the_content','baezone_the_go_url',999);

function baezone_the_go_url($content){

preg_match_all('/href="(.*?)"/',$content,$matches);

if($matches){

foreach($matches[1] as $val){

if( strpos($val,home_url())===false ) $content=str_replace("href="$val"","href="" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val). """,$content);

}

}

return $content;

}

然后在网站根目录下新建个名为 go 的文件夹,在其中写个 index.php 的文件,内容如下(请保存为UTF-8无BOM格式):

$url = $_GET['url'];

$url = base64_decode($url);

?>

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,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,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)}}

补充一点:尽管代码中已经用 base64 将源链接加密,并且加上了 nofollow,但恐怕蜘蛛还是能爬行,所以干脆一不做二不休,在 Robot s 禁止所有蜘蛛爬行 /go?url 目录吧!

二、Simple URLs

Simple URLs是wordpress的一款插件,调用了wordpress本身的发布功能,添加个链接,就向发布文章一样简单,还支持统计链接点击次数哦。


安装插件,启动后,就可以添加新链接,发布了,使用上很简单!需要说明的是,需要空间支持伪静态才能进行跳转哦!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读