Remove Nofollow for Comment Authors with a Simple Function

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?

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

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).

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. :)

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.

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!

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).

Wish your site was as fast as this?

Do It With WordPress is proudly hosted by WP Engine, the very best WordPress hosting that money can buy.

Aside from being blazing fast, it's very secure, has a staging area to test changes before making them live, automated daily backups, malware scanning, stellar support from WordPress experts... It's just everything that you would want from your host, and more.