WordPress为指定分类的所有链接添加nofollow属性

如果出于特殊需求,你要为某个WordPress分类下的文章的所有链接都添加nofollow属性,那你可以将下面的代码添加到主题的 functions.php 文件即可:

1
2
3
4
5
6
7
8
function nofollow_cat_posts($text) {
global $post;
if( in_category(1) ) { // 修改这里的分类ID
$text = stripslashes(wp_rel_nofollow($text));
}
return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

function nofollow_cat_posts($text) { global $post; if( in_category(1) ) { // 修改这里的分类ID $text = stripslashes(wp_rel_nofollow($text)); } return $text; } add_filter('the_content', 'nofollow_cat_posts');

参考资料:http://www.wprecipes.com/how-to-add-nofollow-attributes-to-all-links-in-a-specific-category

全部为采集文章,文中的 联系方式 均不是 本人 的!

发表评论