How to add nofollow attribute to WordPress category specific links

x theme

If you are linking any WordPress category inside your post editor, you can make dynamically make them nofollow.

Following code snippet will help you to add the nofollow attribute to the category links coming from the_content(). Paste the following code inside your functions.php.

function nofollow_cat_links($text) {
global $post;
// Speicify Category ID here
if( in_category(3) ) {
$text = stripslashes(wp_rel_nofollow($text));
}
return $text;
}
add_filter('the_content', 'nofollow_cat_links');

Note: If you want to make all your external links in WordPress, attributed to nofollow dynamically. You can use this plugin.

Related posts:

About the author

admin

Leave a Reply

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