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

WordPress自动给文章添加nofollow属性的实现方法

发布时间:2020-12-14 14:50:23 所属栏目:wordpress 来源:网络整理
导读:本篇章节讲解WordPress自动给文章添加nofollow属性的实现方法。供大家参考研究。具体分析如下: nofollow属性是告诉搜索引擎不传权重过去,但WordPressk中如果我们要nofollow属性就需要手工加了,现在我来告诉大家利用 Nofollow for external link就可

本篇章节讲解WordPress自动给文章添加nofollow属性的实现方法。分享给大家供大家参考。具体分析如下:

nofollow属性是告诉搜索引擎不传权重过去,但WordPressk中如果我们要nofollow属性就需要手工加了,现在我来告诉大家利用 Nofollow for external link就可以自动给文章添加nofollow属性了.

直接安装启用 Nofollow for external link 插件,或者将下面的代码添加到当前主题的 functions.php 文件即可.

实例代码如下:

]*?)1[^>]*>"; if(preg_match_all("/$regexp/siU",$content,$matches,PREG_SET_ORDER)) { if( !emptyempty($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 = '/targets*=s*"s*_blanks*"/'; preg_match($pattern,$tag2,$match,PREG_OFFSET_CAPTURE); if( count($match) < 1 ) $noFollow .= ' target="_blank" '; $pattern = '/rels*=s*"s*[n|d]ofollows*"/'; preg_match($pattern,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; }

(编辑:李大同)

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

    推荐文章
      热点阅读