Overriding WordPress NoFollow Tags

There could be a good reason why you would want to override the WordPress NoFollow tags that are added to your website. I’e been working on closing out some issues picked up by Ahrefs on a site lately.

These could be as simple as looking to gather any potential link juice, or equity, that you may be able to within your site. Or, it may be that you are just looking to reduce the number of issues showing up on your site scans.

Either way, offering a DoFollow link option is something to approach with caution. You’re likely to see a spike in spammy comments, but they are able to be managed.


Matt Cutts had some valuable info to share on the topic of NoFollow tags, which, if you’re looking at this purely from an SEO perspective, it’s worth the read.

The challenge is that doing this isn’t always as easy as it seems. And I’m not a huge fan of filling a website up with plugins and other bloat.

No Plugin WordPress NoFollow Solution

So, how did I enable links in my WordPress Comments sections to be untagged as NoFollow? It took a while, but the solution I found was in adding the following code to the functions.php file in the Child Theme.

 * Comment Remove NoFollow

remove_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 );
remove_filter( 'pre_comment_content', 'wp_rel_ugc', 15 );
function remove_nofollow($string) {
$string = str_ireplace('nofollow', '', $string);
return $string;
add_filter('comment_text', 'remove_nofollow');

 * End Comment Remove NoFollow

Making sure that you have a backup of the original functions.php file is going to be really important here. And changes are so much easier to make using FTP or through your host in my experience (rather in the Theme Editor).

There can be some worrying consequences when you paste the wrong code in the wrong area of the wrong file. This sits nicely in the bottom of the functions.php file in the Child Theme, just before the // END ENQUEUE PARENT ACTION line.

How WordPress handles the NoFollow code

The code used above could have varying degrees of success as individual snippets, and these could be looked upon in the following way.

The below (shown as code line 2 above) may work on its own, but it is very likely that you will need to add another line.

remove_filter( ‘pre_comment_content’, ‘wp_rel_nofollow’, 15 );

It is likely that a UGC tag could still appare, which is where the below (shown as code line 3 above) should help to solve this issue.

remove_filter( 'pre_comment_content', 'wp_rel_ugc', 15 );

It is highly likely that you will need to check any preexisting comments that you want to have as DoFollow to ensure that these have been fixed. If they haven’t, simply go into your Comments section and choose ‘Edit’.

Quick Edit will not give you the option to delete any preexisting HTML that instructs the bots to not follow your lilnks.