源码详情
做站长都知道,无论外链还是用户评论,在SEO方面每个人的手法都是不同的,但不约而同的是:对于站内的外链大多数站长都选择给外链增加NOfollow属性,以此避免站内权重分散传递给外链。 插件使用方法:
方法1:直接安装插件即可,不想用插件的可以参考方法2
方法2:打开我们所用的主题的模板函数文件,也就是functions.php 文件,将下面的代码加到模板函数里面,它会给外部链接自动添加:
add_filter(‘the_content’, ‘auto_nofollow’); //nofollow文章内容的站外链接
add_filter(‘comment_text’, ‘auto_nofollow’); //nofollow评论内容的站外链接
function auto_nofollow($content) {
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback(‘/a]+/’, ‘auto_nofollow_callback’, $content);
}
function auto_nofollow_callback($matches) {
$link = $matches[0];
$site_link = get_bloginfo(‘url’);
if (strpos($link, ‘rel’) === false) {
$link = preg_replace(%(href=S(?!$site_link))%i, ‘rel=nofollow $1’, $link);
} elseif (preg_match(%href=S(?!$site_link)%i, $link)) {
$link = preg_replace(‘/rel=S(?!nofollow)S*/i’, ‘rel=nofollow’, $link);
}
return $link;
}
截图
