How to add nofollow attributes to all links in a specific category

Simply copy the code below and paste it on your functions.php file. Don’t forget to set the desired category ID on line 3.

function nofollow_cat_posts($text) {
global $post;
        if( in_category(1) ) { // SET CATEGORY ID HERE
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

Thanks to Sagive for submitting this function!

Leave a Reply

Your email address will not be published. Required fields are marked *