Remove Nofollow for Comment Authors with a Simple Function

Commenting on WordPress

Back in the day, it was very simple; every link counted for something. However, in 2005, in an effort to battle spam, Google introduced the nofollow attribute to battle people who were leaving comments everywhere they could so that they could keep building their backlinks. The idea of the nofollow attribute is that commenters can still leave their URL, but Google ignores it in terms of PageRank, so it doesn’t have a negative impact on your site if the link leads to a spammy site.

That all sounds well and good, but in the eyes of many (myself included), it’s a case of punishing everyone for the actions of the few. There are still millions of legitimate bloggers who rely on commenting to help build their reputation online and nofollow only hinders that.

There are a few initiatives that aim to help bloggers make the most out of building community by commenting. One of those is CommentLuv (which you will note, is installed here on Do It With WordPress) which allows commenters to leave a link to one of their most recent posts as well as a link to their main homepage.

Another initiative is to remove the nofollow attribute from WordPress, which is included in comment author links as standard. There are a few ways to do this; I don’t recommend editing the core commenting files, because as soon as WordPress is upgraded, you lose your changes.

A second way is to install a plugin that will do it for you. That’s fine and will work OK, but for me, I like to have complete control over my site, so I like to use functions where possible. I finally found a function which does this for you; all you need to do is copy the snippet below into your functions.php file. You can check that it’s worked by looking at the page source both before and after and looking for the removal of rel=”nofollow” from the comment author’s links.

You can also take it a step further and remove the nofollow attribute from all links related to comments, such as links that are left within the comment text itself. To do that, use the following function instead:

Are you in nofollow camp, or have you seen the light and come over to the dofollow camp? How have you handled making your site dofollow?

17 thoughts on “Remove Nofollow for Comment Authors with a Simple Function”

  1. Unknown says:

    Another way to promote your blog would be to use a readable font. That embossed thing you use is excruciatingly annoying to read.

    1. As blunt as your criticism is, I still appreciate it; it’s a comment I’ve heard before, so I’m going to try removing the shadow and see how it looks. Thanks

  2. Vincent Raja says:

    Wow it was very easy and simple step.. actually my blog is dofollow but i was using Plugin for this in my blog.. Let me do this change and remove that plugin. Thanks

    1. Thanks Vincent. I was using the plugin too, but for such a simple action, I was sure there had to be a function that could handle it. It wasn’t easy to come by, but I got there in the end. Hope it works for you. Let me know if you hit any trouble

  3. Jasmine says:

    Great tips. However, what will happen when we upgrade WP in the future? Will we lost the changes and have to make our hands dirty again by editing the code?

    1. When you need to upgrade WordPress, your functions.php file will be fine. However, if your theme gets updated (if its from the official WordPress directory), then it will overwrite your functions.php file. That’s why i always use a funcionality plugin with my sites, so that upgrades never affect my customizations (tutorial on that coming soon).

      1. Jesse V says:

        Dave, great article you shared mate.

        Janice, I believe using Child theme will keep all your modifications intact since child theme has separate functions file. I didn’t know about using Child theme before but when I tried it, it’s fun and will save you from all future updates whether you’re updating WP core script or theme. I hope that helps. :)

  4. AstroGremlin says:

    You made me aware that commenters were getting no juice. I may use the code some day, but for now I just activated the plugin Remove Nofollow. Thanks!

    1. Yeah the plugin does the trick just fine – it’s just a preference I suppose. I’d rather cover something with a function if possible.

  5. Dan says:

    If you don’t feel safe playing around the backend coding of WordPress, you can always use a plugin to remove nofollow attribute for you.

    I’d suggest using the Semiologic plugin found here:

    It still works on the latest WordPress 3.2.x version.

    1. Indeed. That’s the plugin I was referring to in my write-up. It’s definitely a quick fix for anyone who is a bit daunted by touching code.

  6. Xps says:

    I copy/pasted the first script and it gave the following error instead of displaying the author names for both those that did and didn’t supply a URL:
    Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 5 in {My test site}/wp-content/themes/twentyten/functions.php on line 528
    Line 528 of my theme’s function.php is line 7 of your script.

    I did, however, find it easy to remove nofollow from comment author names by editing the WP core. In /wp-includes/comment-template.php line 155 (inside the get_comment_author_link function), omit “nofollow” from the relation attribute. Since it is a core file adjustment, you’ll need to reapply the change each time WP updates that file, but it’s a quick change.

    The second script gives the same error as the first by replacing the comment author and the comment itself whether or not either have URLs. I’ve yet to find a solution to remove nofollow from comments, but I’ll keep looking. Like you, I prefer hard-coding small adjustments instead of installing plugins.

    P.S. I only just found your site tonight and it’s definitely worth a bookmark. Good effort.

    1. Thanks for your comment. I’m not sure what the issue with the function on your site is without being able to see it, but I avoid editing the WordPress core at all costs, not because I’m afraid of messing something up, but just because it’s unwise and as you rightly pointed out, it’s something you have to remember to do every time you update WordPress, which is just another thing to worry about IMO. I’d try and see what the problem is with the function and repair it. If you find a solution, I’d be grateful if you’d post it here in case other people are having the sam problem. Thanks!

  7. AstroGremlin says:

    I’m now using CommentLuv to manage Do Follow. I’m assuming that takes the place of either the remove No Follow code or the other plugins. Is that accurate?

    1. Well, CommentLuv does provide you with a dofollow link, but it won’t change the website link from nofollow, so if you want to make both links dofollow, you’ll still need to use this function (or a plugin).

      1. AstroGremlin says:

        Appreciate it, Dave. Just reactivated the NoFollow Free plugin.

  8. Karl says:

    The remove from all comment code no longer appears to work. With PHP v7, I get the following error:

    PHP Warning: preg_replace(): Compilation failed: unmatched parentheses

Leave a Reply