百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【站长工具】WordPress为指定分类的所有链接添加nofollow属性

发布时间:2020-09-17

作品分类:站长工具  添加  分类  那你  属性  指定  添加  链接  分类

如果出于特殊需求,你要为某个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');

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

Top