当前位置: 首页 > 收藏夹 > wordpress博客文章中外链添加nofollow属性

wordpress博客文章中外链添加nofollow属性

发布于:2013-10-14 最后更新:2018-8-4 收藏夹 0条评论 1,975 views
本站提供Linux服务器运维,自动化脚本编写等服务,如有需要请联系博主微信:xiaozme

只要在主题的functions.php文件中添加下列代码即可,代码只会对外链添加external nofollow,不会改变站内链接属性。

// 自动给文章的外部链接添加nofollow属性
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($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=\"$val\" rel=\"external nofollow\" ",$content);
  }
 }
 return $content;
}

原文来自:wordpress博客文章中外链添加nofollow属性 ,最终解释权归原作者所有,如有侵权,请联系QQ:337003006删除。


发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注