Hacking WordPress: Dofollow Whitelist for Commentator Links

by Jeff Starr on Tuesday, September 18, 2007 19 Responses

[ 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.
  • With a simple modification, we can turn our “dofollow whitelist” into a “nofollow blacklist.”
  • Blog owners may wish to reward their favorite commentators with a little link love.
  • 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.


19 Responses

Add a comment

[ Gravatar Icon ]

Bape#1

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

[ Gravatar Icon ]

Perishable#2

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’?

[ Gravatar Icon ]

Alex#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.

[ Gravatar Icon ]

Perishable#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.

[ Gravatar Icon ]

Florentina#5

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.

[ Gravatar Icon ]

Perishable#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!

[ Gravatar Icon ]

Lee#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

[ Gravatar Icon ]

Perishable#8

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

[ Gravatar Icon ]

Iuli#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.

[ Gravatar Icon ]

Perishable#10

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

[ Gravatar Icon ]

Epic Urls#11

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.

[ Gravatar Icon ]

Jeff Starr#12

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.

[ Gravatar Icon ]

Iuli#13

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.

[ Gravatar Icon ]

Jeff Starr#14

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

[ Gravatar Icon ]

Qrystal#15

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

[ Gravatar Icon ]

Jeff Starr#16

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

[ Gravatar Icon ]

computer#17

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.

[ Gravatar Icon ]

Jeff Starr#18

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

[ Gravatar Icon ]

Jerom#19

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

Share your thoughts..

Read Comment Policy

Comment Rules: No spam. No profanity. Use your real name. You may use simple HTML tags for style. Wrap all code in <code> tags. Learn more.



Attention: Do NOT follow this link!