一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

wordpress自动给文章的外部链接添加nofollow属性

时间:2013-04-24 编辑:简简单单 来源:一聚教程网

到正题,除了每次手工给外部链接添加nofollow外,还可以通过以下程序代码来实现自动给文章内容中的外部链接添加nofollow属性。

将以下代码添加到当前主题文件夹下的functions.php文件中即可:

 代码如下 复制代码

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属性

给标签云添加nofollow属性的方法也很简单,在你的主题文件夹下的functions.php文件夹下加入如下代码即可:

 代码如下 复制代码

add_filter('wp_tag_cloud','web589_tag_cloud_nofollow');
function web589_tag_cloud_nofollow($cloud){
 $cloud=preg_replace('/  return $cloud;
}

屏蔽评论者链接


在主题文件夹下的functions.php中加入代码:

 代码如下 复制代码

add_filter('get_comment_author_link','web589_comment_author_link');
function web589_comment_author_link($link){
  $args=array('//','//');
 $link=preg_replace($args,'',$link);
 return $link;
}

热门栏目