Welcome to the new design! Please report any bugs or issues, thanks :)
Web Dev + WordPress + Security

Hacking WordPress: Dofollow Whitelist for Commentator Links

[ Image: Inverted Eye Detail ] Before repenting of my filthy “nofollow” addiction, I experimented briefly with a “dofollow whitelist” for commentator URL links. The idea behind the whitelist is to reward frequent commentators, feed subscribers, site patrons, and other guests by selectively removing the automatically generated nofollow attributes from their associated comment-author links. For nofollow enthusiasts, a dofollow whitelist is a great way to show appreciation for people who support your blogging efforts.

Now, before we go hacking away at WordPress, keep in mind that there are a few potential shortcomings to this method. First of all, manually maintaining such a list would eventually fail. It simply would require too much work. Perhaps as an automated WordPress plugin, a dofollow whitelist would be a reasonable solution. A dofollow whitelist plugin would also eliminate the need to hack the WordPress core, which the following hack definitely requires. Other issues involve duplicate author names and user verification. Nonetheless, even as an elementary WordPress hack, a dofollow whitelist for comment signature links may prove useful. Here are a few examples:

  • Blogs wishing to encourage user registration may sweeten the deal by removing nofollow attributes from member links.
  • Sites featuring multiple guest bloggers may wish to serve dofollow links to their collective authorship to share link equity.
  • With a simple modification, we can turn our “dofollow whitelist” into a “nofollow blacklist,” for SEO purposes and such.
  • Blog owners may wish to reward their favorite commentators with a little link love. This encourages user activity on your site.
  • A savvy programmer with some free time may use it to develop a WordPress plugin ;)

Thus, with its potential usefulness in mind, let’s hack ourselves a WordPress dofollow whitelist for comment signature links..

Hacking a WordPress dofollow Whitelist

Selectively serving dofollow links involves selectively removing WordPress’ automatically generated nofollow links. WordPress adds the nofollow attribute via the function get_comment_author_link(), which is located in the file wp-includes/comment-functions.php in WordPress 2.0 and wp-includes/comment-template.php in WordPress 2.1 and 2.2. After locating the function, we find something similar to this:

function get_comment_author_link() {
	global $comment;
	$url    = get_comment_author_url();
	$author = get_comment_author();

	if ( empty( $url ) || 'http://' == $url )
		$return = $author;
	else
		$return = "<a href='$url' rel='external nofollow'>$author</a>";
	return apply_filters('get_comment_author_link', $return);
}

In this function, WordPress differentiates between linked comment signatures and unlinked (empty) comment signatures, formatting output accordingly. As you can see, when the comment author provides a URL, WordPress fashions a linked signature featuring the infamous external nofollow attribute. We need WordPress to further differentiate comment links based on whether or not the author is found on our whitelist. Sure enough, injecting an elseif() conditional statement does the trick:

// [ Dofollow Whitelist ] WordPress 2.0, 2.1, 2.2 >>
function get_comment_author_link() {
	global $comment;
	$url    = get_comment_author_url();
	$author = get_comment_author();

	if ( empty( $url ) || 'http://' == $url )
		$return = $author;
	elseif ( $author   == 'select username 1' 
			|| $author == 'select username 2' 
			|| $author == 'select username 3' 
			|| $author == 'select username 4' 
			|| $author == 'select username 5' 
		)
		$return = "<a href='$url' rel='external'>$author</a>";
	else
		$return = "<a href='$url' rel='external nofollow'>$author</a>";
	return apply_filters('get_comment_author_link', $return);
}

The new condition checks all comment authors against our username whitelist and serves a fully functional, dofollow link for each of them. Simply add and edit a new || $author == 'username' line for each selected name. As mentioned, I used this method for several weeks here at Perishable Press before finally deciding to eliminate nofollow attributes once and for all.

Jeff Starr
About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
The Tao of WordPress: Master the art of WordPress.

21 responses to “Hacking WordPress: Dofollow Whitelist for Commentator Links”

  1. I’m sorry if i offended you, it wasn’t my intention. But you are wrong. I do read all the articles i comment on, i have a 1200 words/min reading speed, so it realy doesn’t take much to read a blog post.
    I didn’t meant to say your article is very bad as you understood. What i wanted to say is this: part of my job is linkbuilding, i used to love it because i had the opportunity to read lots of interesting stuff during working hours and do my job in the same time. I never spammed, because there was no need to, i already read the article, why not comment on it?!?
    I also don’t get it why you call Upper a “scumbag” site. And from where do you drop the conclusion that i’m an imbecil. For your information, i do have an 136 IQ, I speak 7 languages and i have a master degree in Philosophy and one in Literature. Also i have a published paper on blog-literature, for which i researched during linkbuiling.
    So just because i comment for links, doesn’t mean i’m spamming. Also i’m sure you would be fine if my comment was something like :”great article, i love it”:))
    PS. I don’t expect you to publish my comments, i just wanted you to know how wrong you are, and how vain. Good luck with blogging and all.

  2. Jeff Starr

    Hi luli, if I misunderstood your meaning or intention, I apologize. Rather than make excuses for my accusatory message, I want to thank you for helping me to understand your point of view. I think I understand where you are coming from now, and appreciate the fact that you took the time to explain yourself here at Perishable Press. Thank you! :)

  3. I really wish I could put together a plugin that could make a dofollow whitelist! This seems like the perfect answer, because it completely avoids the problems of maintaining a blacklist: you DON’T have to keep as regular with it! A whitelist would be an awesome reward, and I’m currently looking for an easy way to reward a commenter for a great comment on my blog. Shame it’s not just a plugin away… yet?

    I’m subscribing, in the hopes that someone in the LazyWeb finds me that plugin I so desire..! :P

  4. Jeff Starr
    Jeff Starr 2008/09/27 7:03 pm

    Hi Qrystal, there are plugins with whitelist/blacklist functionality. Check out my official Dofollow Reference for WordPress. They may not provide the exact functionality you are after, but some of them certainly come close. One of these days, I do intend to develop a custom dofollow plugin that is centered around the whitelist/blacklist concept. Thanks for the comment, and for subscribing! :)

  5. It is easier to search for forums with nofollow links than it is to search for follow links. In order to automate the process you could write a script that search for blog with high PR, store it in a file, then parse it looking for the nofollow string.
    Throw away all the results with nofollow and what you have left is the follow stuff.
    I could easily write up a python or bash script to do it.

  6. Jeff Starr
    Jeff Starr 2008/11/09 5:13 pm

    @computer: sounds good! Where can I download a copy?

  7. could I join Jeff Starr’s list?
    10x
    J

  8. HI. Is there any trick by which we can post dofollow links on wordpress sites. Actually my job is to post dofollow links for other websites on other sites. But most of the time i fail cuz most of the sites i get are wordpress, blogspot or disqus sites. Is there any trick or hack to make dofollow link on such sites available ??? Please mail me if there is any.

    Thanks. Waiting for your reply.

  9. Jeff Starr
    Jeff Starr 2010/04/21 5:07 pm

    @divya: Actually there’s not an actual dofollow attribute. That’s just what you call a link that does include a nofollow attribute value.

    Check out the “Related Articles” links at the end of the post. There you will find some in-depth information about removing nofollow from WordPress sites.

    Not sure about doing the same for blogspot or disqus sites.

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
WP Themes In Depth: Deep dive into WP theme development.
Thoughts
Playing the long game.
They have weaponized the idiots.
Good software never steals focus from the user. Even during startup.
After 10 years running my own business, I still manage schedules and tasks using old school post-it notes, sometimes simple sometimes very elaborate.
You know those sites, where you're trying to just grab a quick bit of information but the page is shifting all over the place as it loads up 3 million advertisements.
Selling two of my top WordPress domains, wp-zen.com & zen-wp.com $300 for both. Aged 9 years. Drop a line if interested.
Never force your users to type out a password (or any long string of characters) by blocking the paste function. Typing long strings leads to MORE errors than simple copy/paste.