Adding the nofollow attribute in WordPress Tag Cloud and tag links
I like the Wordpess tag cloud. It’s nice to see with a glimpse of an eye, the topics that are most discussed on one’s blog. However, my very good friend and SEO guy James Morris told me many times to NOT USE the tag cloud unless it’s modified to add the nofollow attributes on links.
I started looking for a solution and find this one. A very interesting solution. Jan has made a patch to edit the Tag cloud widget to add an option for nofollow tag. Unfortunately, his change was not accepted by the WordPress team because average user would not understand what the nofollow setting does. Which makes sense by the way and explains why WordPress is so great. They always ensure that by default, an average user will understand what he sees. I like that. And anyway, plugins exists specifically for that reason: adding extra things you need!
So Jan is proposing an alternative. Simply add this code at the end of your wp-congig.php file, which works perfectly:
add_filter( 'wp_generate_tag_cloud', 'my_nofollow_tag_cloud_example' );
function my_nofollow_tag_cloud_example( $text ) {
return preg_replace_callback('|<a>|i', 'wp_rel_nofollow_callback', $text);
}
</a>
However, I also find a plugin that does exactly this. It’s basically the same code, but added in a plugin so no change is required on core file. Also, if you want to add the nofollow attribute on the tag links disokayed on bottom of each post, you can simply uncomment the last line in the plugin file:
//the_tags
add_filter('the_tags', 'szub_nofollow_tag'); // uncomment this line to hit tag links from the_tags()
And this is the plugin I’m now using here. Thank you thinkjayant and WordPress community!
Does the addition to the bottom of the wp-config file mean that you would need to redo it each time you upgrade to a new version of wordpress?
Thanks
Yes, and this is why the second alternative I’m proposing is better because it’s in a plugin, so no chance to the core of WordPress is needed.
Hope this helps !