The Deluxe One-Minute Dofollow WordPress Upgrade

After our previous article, we all know how easy it is to kill the default nofollow attributes that WordPress automatically injects into all commentator, trackback, and pingback links. Indeed, our original one-minute upgrade delivers dofollow links across the board, effectively passing the love juice to every type of response. Fine for some, but some need more..

In this article, we improve the original dofollow upgrade by differentiating between the three different response types. With our “deluxe” model, nofollow attributes may be removed selectively from trackbacks, pingbacks, commentator links, or any combination thereof. For example, you may remove nofollow from commentator links while dishing full juice to trackbacks and pingbacks.

Ready? Let’s do this thing..

Step 1) First, open the file wp-includes/comment-functions.php and locate the function get_comment_author_link(). In WordPress 2.0, 2.1, and 2.2, we see 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);
}

Step 2) Next, upgrade that dry, crusty default code with our juicy deluxe model:

// Deluxe One-Minute Dofollow WordPress Upgrade
function get_comment_author_link() {
	global $comment;
	$url    = get_comment_author_url();
	$author = get_comment_author();
		if ( empty( $url ) || 'http://' == $url )
			$return = $author;
		elseif ( $comment->comment_type == 'pingback' )
			$return = '<a href="'.$url.'" rel="external nofollow">'.$author.'</a>';
		elseif ( $comment->comment_type == 'trackback' )
			$return = '<a href="'.$url.'" rel="external nofollow">'.$author.'</a>';
		else
			$return = '<a href="'.$url.'" rel="external nofollow">'.$author.'</a>';
	return apply_filters('get_comment_author_link', $return);
}

Step 3) Finally, remove any/all of the three nofollow attributes that you desire. Upload, check, and done!

Final thoughts..

Beyond the selective deliverance of piping hot G-juice, the “Deluxe One-Minute Upgrade” (hey, I had to call it something) provides complete control over the markup and presentation of commentator links, trackbacks, and pingbacks. If anything, look at this hack as a friendly way into the dark heart of the WordPress core. Use it to incorporate response-specific (X)HTML markup, CSS styles, DOM behaviors — whatever! After the customization of your nofollow strategy, the sky’s the limit!