Spring Sale! Save 30% on all books w/ code: PLANET24
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.

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
USP Pro: Unlimited front-end forms for user-submitted posts and more.

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

  1. Its ironic that many bloggers talk about this but then they actually use no follow.

  2. Perishable 2007/09/28 7:52 pm

    Well, you know, there are legitimate reasons for selective application of nofollow attributes. For example, some bloggers prefer to serve borderline spam comments with nofollow links in an effort to thwart losers who drop brainless comments just for the link love. You know what I’m sayin’?

  3. I get so much spam as it is on my blogs without dofollow enabled, I can’t imagine what it’s like with it. I still get SEO people on my blog using names like “SEO Services” in the nick name part of the comment.

  4. Me too, but I don’t mind sharing juice with a few spammy types if it means that legitimate commentators will be shown some appreciation for their commenting efforts.

    If I were feeling argumentative, which I’m not currently, I would say that 99.9999% of all comments are in one way or another nothing but spam.

    Everyone knows what comments are used for, but only a few people are uptight enough to worry about it.

  5. Florentina 2007/12/15 1:11 am

    I admit i have nofollow comment links on my blog because i receive tons of spam ,not one single comment worth approving cuz i would. I’d like people to leave a smart comment on my blog, even if their only interest is to get a link back but i only get stupid comments.

  6. Sorry to hear that, Florentina. Although I have been blessed with some great feedback here at this site, I have a few other blogs that receive nearly 99% spam-type comments. For a couple of those sites, I am actually planning on removing comments altogether — it’s just not worth it!

  7. I’m looking for a WordPress template that will work well for intergration with oscommerce. Ideally, a wordpress plugin that will work well for a product list of about 30 items. Oscommerce may be overkill. If anyone has any info on this, please leave a follow up post:)

    Thanks,

    Lee

  8. Perishable 2008/04/21 5:23 pm

    Hi Lee, unfortunately I am unfamiliar with anything that might suit your needs. Hopefully, there is someone out there with some helpful information. In any case, thanks for dropping by the site. Good luck! :)

  9. I realy hate nofollow. I do comment mostly for links but i always try to give some feedback or a reason for the blogger to approve my comment. My job was so much fun when i could comment on any given blog. I had a choice and i would choose only the blogs i like. Now all the interesting ones are nofollow :( and i have to comment on low quality articles… I hate spam too, but this nofollow thing doesn’t seem like a good solution to me.

  10. Perishable 2008/07/20 7:39 am

    @luli: perhaps true, but mindlessly dropping links to scumbag sites like “upper-webmarketing.ro” is just as bad. Here’s what I see, tell me if I’m wrong: in your quest to get as many links as possible, you leave authentic-looking comments on every well-ranking dofollow blog you can get your hands on. You ramble on about something even remotely related to the topic, without actually thinking about what it is that you’re saying. Occasionally, this pseudo-spamming method fails to work, but most of the time people aren’t paying attention, so you manage to get away with it. Your comment left here is a perfect example of this. You begin by reiterating the general theme of the article, then proceed to admit that your job involves leaving spam comments. Even worse, you then go on to insult me, my site, and my readers by whining about how you can no longer spam the blogs you “like” because they now are all nofollow. As if that weren’t enough, you complain that you now have to comment on “low-quality” articles, of which the above post must qualify. Does that sound about right to you, “luli”? Or did I miss something? I guess it’s not much of a mystery why all of your primary (high PR) spam targets are no longer dofollow — because idiot spammers like you RUIN IT for the rest of us. Why don’t you pull your head out of your spamhole and think about what you are doing before acting like a mindless imbecile.

  11. Epic Urls 2008/09/14 9:06 pm

    Great post, thanks for the information. I think nofollow was only suggested by Google because they do not have the resources to truly eliminate artificial link building.

  12. Jeff Starr 2008/09/15 8:37 am

    Perhaps, or they could be doing it to facilitate the creation of consolidated mainstream channels of web content such as Wikipedia, Google Knol, and YouTube. Links check in, but they don’t check out.

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 »
Wizard’s SQL for WordPress: Over 300+ recipes! Check the Demo »
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.