Popular

Post: How to disable nofollow in WordPress

NoNoFollow: Fight spam, not blogs.

You maybe already heard about the nofollow tag, invented by Google to prevent spam. In fact, it doesn’t prevent or decrease spam at all, and a lot of criticism has been expressed against it. Some of the reasons why you shouldn’t use nofollow are summed up at NoNoFollow, and a recent post about Google’s mistake is available here. Below, I’ll explain how to simply remove the nofollow tag from WordPress, without the need to install a plugin.

All you need to do is edit three files, wp-includes/default-filters.php, wp-includes/functions-formatting.php and wp-includes/comment-functions.php. In default-filters.php, a filter is set which adds the nofollow tag to links in comments. You need to change the following line (around line 28):
add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
Comment it out, so it becomes:
//add_filter('pre_comment_content', 'wp_rel_nofollow', 15);

In functions-formatting.php, the make_clickable() function searches for links in comments to make them clickable, but not followable by search engines. Search the following (normally from line 572 to 579):

function make_clickable($ret) {
        $ret = ' ' . $ret . ' ';
        $ret = preg_replace("#([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])#i",
> "$1<a href='$2://$3' rel='nofollow'>$2://$3</a>", $ret);
        $ret = preg_replace("#(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)#i",
> "$1<a href='http://www.$2.$3$4' rel='nofollow'>www.$2.$3$4</a>", $ret);
        $ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([a-z0-9\-_.]+)\.([^,< \n\r]+)#i",
> "$1<a href=\"mailto:$2@$3.$4\">$2@$3.$4</a>", $ret);
        $ret = trim($ret);
        return $ret;
}

And paste the following over it:

function make_clickable($ret) {
	$ret = ' ' . $ret . ' ';
	$ret = preg_replace("#([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])#i", "$1<a href='$2://$3'>$2://$3</a>", $ret);
	$ret = preg_replace("#(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)#i", "$1<a href='http://www.$2.$3$4'>www.$2.$3$4</a>", $ret);
	$ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([a-z0-9\-_.]+)\.([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3.$4\">$2@$3.$4</a>", $ret);
	$ret = trim($ret);
	return $ret;
}

The last change is in the file comment-functions.php, where the get_comment_author_link() function returns a link to the website of a commenter. Edit the following line (should be around line 378):
$return = "<a href='$url' rel='external nofollow'>$author</a>";
And change it to:
$return = "<a href='$url' rel='external'>$author</a>";

Feel free to comment on this post, links will be displayed and followed by search engines!

Advertisement

Comments on "How to disable nofollow in WordPress"

RSS

There's a total of 11 comments to this post. Add yours below.

Replies

Trackbacks

The trackback URI of this post is http://jw.x10hosting.com/blog/2006/05/27/how-to-disable-nofollow-in-wordpress/trackback/

Pingbacks

Leave a reply on "How to disable nofollow in WordPress"

Feel free to express your opinions, remarks, comments, ideas, observations, notes, interpretations, thoughts, love or hate here. You can even use Textile to format your comments, some nice shortcuts are built in into the toolbar below.

Concerning spam: don't provide links to your website if it's completely irrelevant, I will remove links to websites that for instance provide loans or cheap insurances. Please also write your comment in clear English, not in some gibberish English no one really understands. Comments are filtered by Spam Karma 2 to prevent all kinds of spam.

(This will not be published.)

Textile controls (requires JavaScript):