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

wp教程评论72阅读模式

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

1
2
3
4
5
6
7
8
 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

宜家网
  • 本文由 发表于 2022年1月19日 23:40:28
  • 转载请务必保留本文链接:https://www.yjro.com/31324.html

发表评论