Skip to content

Instantly share code, notes, and snippets.

@bewho
Created September 12, 2017 10:04
Show Gist options
  • Save bewho/d6b1e91de36e690c8e456efe8c4c1369 to your computer and use it in GitHub Desktop.
Save bewho/d6b1e91de36e690c8e456efe8c4c1369 to your computer and use it in GitHub Desktop.
Add nofollow attribute to category specific links
//Adding this snippet to the functions.php of your wordpress theme will add the nofollow attribute to category specific links within the_content.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment