WordPress自动外部链接加上nofollow标签且新窗口打开
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

如果我们网站可能需要特殊的细节注意问题,在内容文章之间跳转到外部地址,可能需要注意权重传递。这里我们可以将链接标签加上nofollow标签。我们可以在加上每个外部链接的时候自己手工添加,也可以用下面的办法实现自动添加nofollow标签,以及将这些外部链接全部用在新窗口打开。
// 内容页nofollow标签属性以及新窗口打开
add_filter( \’the_content\’, \’cn_nf_url_parse\’);
function cn_nf_url_parse( $content ) {
$regexp = \”<a\\s[^>]*h=(\\\”??)([^\\\” >]*?)\\\\1[^>]*>\”;
if(preg_match_all(\”/$regexp/siU\”, $content, $matches, PREG_SET_ORDER)) {
if( !empty($matches) ) {
$srcUrl = get_option(\’siteurl\’);
for ($i=0; $i < count($matches); $i++)
{
$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];
$noFollow = \’\’;
$pattern = \’/target\\s*=\\s*\”\\s*_blank\\s*\”/\’;
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= \’ target=\”_blank\” \’;
$pattern = \’/rel\\s*=\\s*\”\\s*[n|d]ofollow\\s*\”/\’;
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= \’ rel=\”nofollow\” \’;
$pos = strpos($url,$srcUrl);
if ($pos === false) {
$tag = rtrim ($tag,\’>\’);
$tag .= $noFollow.\’>\’;
$content = str_replace($tag2,$tag,$content);
}
}
}
}
$content = str_replace(\’]]>\’, \’]]>\’, $content);
return $content;
}
将代码加入到当前主题的Functions.php文件中,然后我们只要内容中有外部链接,会自动加上nofollow和_blank标签属性。
[Nofollow标签]历史优惠活动内容
猜你可能想看的VPS
- bootstrapTable 设置行样式(背景颜色)全球[VPS测评]
- 搬瓦工最便宜的 CN2 GIA VPS 补货→DC6 1 核 512M 全球[VPS测评]
- Truxgo Servers→$160 月 L5630 8GB 内存 1韩国VPS[主机]
- laravel 中怎么使用原生 sql?全球[VPS测评]
- php 获取当前时间戳全球[VPS测评]
- 大硬盘 VPS $2.25 每月 1G 内存 100G 硬盘 5T 月流全球[VPS测评]
- Xshell Xftp XshellPlus 5 和 6 版本官方下载+全球[VPS测评]
- 应用程序无法正常启动(0xc0000142) 请单击‘确认’关闭应用程序全球[VPS测评]
- PHP 随机生成 N 个汉字 PHP 随机生成一段汉字全球[VPS测评]
- 360 安全防护中心无法开启的解决方案全球[VPS测评]
- CCleaner Pro 最新版 免注册码 绿色破解全球[VPS测评]
- ZeptoVM 512M内存 10G SSD 320G流量 1G带宽 伯全球[VPS测评]
- 40火伞高压电爬坡更让企业用电于民全球[VPS测评]
- 原创解析:云计算含义及定义全球[VPS测评]
- 谷歌浏览器网址如何显示http,www,Chrome谷歌浏览器恢复地址栏全球[VPS测评]
- tudcloud,香港沙田大带宽vps特惠7折,CN2+BGP直连,10香港VPS[主机]
- 1分钟快速读懂云计算全球[VPS测评]
- 147SEO采集器 CSS选择器写法案例全球[VPS测评]
- 桔子数据:1核1GB香港CN2 GIA vps促销28元/月,最高30M香港VPS[主机]
- 小欢互联:洛杉矶高防vps年付138元,香港CN2线路月付8元起,1核/香港VPS[主机]
- 日主机,便宜美国CN2高防VPS¥19/月起,1Gbps带宽,香港多IP站群服务器[IP]
- RangCloud:新购NAT VPS,256/512/1G/2G主机季香港VPS[主机]
- 恒星云:喜迎新春香港CN2云服务器,首月9.9元;深圳2核4G云服务器仅香港VPS[主机]
- 腾讯云香港服务器需要备案吗?腾讯云香港轻量服务器优惠活动香港VPS[主机]
- VPSPlayer,超便宜香港cn2线路小带宽VPS,2核4G内存仅30香港VPS[主机]
- 老六云:⾹港⼤宽带服务器、香港大带宽vps_新购⾸⽉85折优惠香港VPS[主机]
- 阿里云香港vps怎么样?阿里云香港、新加坡云主机如何购买?香港VPS[主机]
- 很简单的图片不规则布局样式,纯css样式实现的图片瀑布流布局全球[VPS测评]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- 自适应bootstrap左侧导航可关闭全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-39946.html











