No NoFollow, No Plugin, No Problem! Three Simple Steps!
Vlad the Affiliate sent me a WordPress Code question through my contact form. You can ask me a question too, and I'll post the answer for you here.
Vlad has been following the discussion on Andy's Blog about CPU issues with LunarPages hosting accounts. He says that while his blog is smaller and receives less traffic than Trisia's Blog, he too has had problems with his host telling him his wordpress installation is too CPU intensive.
Vlad thinks he has narrowed his biggest problem down to his use of a dofollow plugin. When a post has several comments and receives a significant amount of traffic, it seems that all of the modifying of the already modified links in the comments section really puts a strain on his server.
Vlad needs to throttle back some of the resource usage, but at the same time he wants to continue to offer followed links to people who comment on his blog. He asked me if I could show him how to disable nofollow without using a plugin.
I, of course, couldn't refuse Vlad.
Before we start, lets go over a couple of important notes.
- You will be modifying the core WordPress Code in order to do this. These are simple edits, but it is a modification to core files.. That means, make back ups and test it, don't just trust me. It works here, I'm using this on this blog right now. But it might come out differently for you and your configuration. If it does, let me know and I'll see what I can figure out.
- This posts assumes you are using WordPress version 2.2.2. This will probably work fine with some other recent versions, but I make no promises, and won't even think about looking at problems you run into until you are running 2.2.2.
- If you use a lot of plugins, and your host is giving you grief, this is a start, but you may have other problems as well with other plugins (or with your host - I use and recommend http://hostforweb.com/).
- Every time you upgrade WordPress you will have to re implement these changes to remain a dofollow blog.
Okay, now, there are three steps to disabling nofollow in your comments and the second two are optional. Just depends on how dofollow you want to be.
First, the main thing is simply getting the Author's URL link to be dofollow. To do this you need to open the comment-template.php file in your /wp-includes/ folder. Find this section of code at around line
[php num=40]
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 = "$author";
return apply_filters('get_comment_author_link', $return);
}
[/php]
Now just delete the nofollow at around line 48 (on 48 in the example here) so it looks like this.
[php num=48]
$return = "$author";
[/php]
At this point your blog is technically a dofollow blog because you follow the Authors URL in comments. The next two steps are optional, and it's up to you to implement them or not.
The second step as I see it, because the third step is just a lot more common with people seeking to abuse your hospitality. This step will cause any URLs typed into the comments to be followed links as well.
You need to open your formatting.php file in your /wp-includes/ folder, and find this section of code at around line 617.
[php num=617]
function make_clickable($ret) {
$ret = ' ' . $ret;
// in testing, using arrays here was found to be faster
$ret = preg_replace(
array(
'#([\s>])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is',
'#([\s>])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is',
'#([\s>])([a-z0-9\-_.]+)@([^,< \n\r]+)#i'),
array(
'$1$2',
'$1$2',
'$1$2@$3'),$ret);
// this one is not in an array because we need it to run last, for cleanup of accidental links within links
$ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret);
$ret = trim($ret);
return $ret;
}
[/php]
On lines 626 and 627 delete the rel="nofollow" from each lin so they look like this.
[php num=626]
'$1$2',
'$1$2',
[/php]
now when someone types in a URL it should be clickable and it should be followable.
This last step is probably the one you should think longest about. If some one is trying to really spam you they will most often use actual hyperlinks like these. So wether you allow these to follow or not is a bigger decision. Personally, i believe they spammers will spam anyways, so I would make the modification and have these dofollowed.
Open your default-filters.php file in your /wp-includes/ folder and locate this section of code.
[php num=15]
// Comments, trackbacks, pingbacks
add_filter('pre_comment_author_name', 'strip_tags');
add_filter('pre_comment_author_name', 'trim');
add_filter('pre_comment_author_name', 'wp_specialchars', 30);
add_filter('pre_comment_author_email', 'trim');
add_filter('pre_comment_author_email', 'sanitize_email');
add_filter('pre_comment_author_url', 'strip_tags');
add_filter('pre_comment_author_url', 'trim');
add_filter('pre_comment_author_url', 'clean_url');
add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
add_filter('pre_comment_content', 'balanceTags', 30);
[/php]
On line 27 (the line that contains 'wp_rel_nofollow' insert two slashes ( // ) at the beginning of the line to comment this line out so it looks like this.
[php num=27]
//add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
[/php]
And that's it. Now actual hyper links will be dofollow too.
If you have any problems implementing this change be sure to let me know. Happy blogging and happy dofollowing.
Trackback URL for this post:
Bookmark & Share: Click, Copy and Link:








Uhm... messing with the core
Uhm... messing with the core code. I'll always end up doing something wrong. This time I'll definitely backup my site! :)
Thanks for showing us how to do this.
I'm really confused on this
I'm really confused on this area. I do think that the nofollow is not the right way to do it and it ruins it for a lot of other people. However many blogs I used to read got spammed so badly.
[...] wenig im Quellcode der
[...] wenig im Quellcode der Software rumgebastelt und die dafür verantwortlichen Zeilen gelöscht. Geht ganz einfach >> (Alternativ auch per [...]
excellent blogg !
excellent blogg !
Thanks for this Dane. I've
Thanks for this Dane. I've been looking for a way to make all pages dofollow. I had to switch OZ to Wordpress to do it.
It works in Wordpress MU as well, just in case anyone is wondering.
Its ironic that many
Its ironic that many bloggers talk about this but then they actually use no follow.
Nice tutorial :) I wold like
Nice tutorial :)
I wold like to test in on my blog
interersting. I'll try
interersting.
I'll try asap
thank you
[...] I just went ahead and
[...] I just went ahead and removed that code myself. If you want to do the same, I recommend reading this post on Blogstrokes. It should give you all the [...]
@Shea and Andy, Yep. Your
@Shea and Andy,
Yep. Your both right. Hard coding changes in the core code is not ideal. I rarely do it myself and even more rarely suggest that anyone else do it. And yes, plugins are handier, in so many ways.
All that said, there are times when hard coding may be the way to go to accomplish something you want to accomplish. At least temporarily. I used to have a lot of hard coded hacks on danemorgan.com, but I have only a handful there now, and most of those, only because I haven't taken the time to remove them.
I really liked this particular example though because it demonstrates a couple of things.
First, it's simple. I removed three words and added two slashes to accomplish what would require several lines of plugin code. This shows that it's a doable thing and you could even use a macro in a good text editor to make these changes in future updates very easily.
Second it calls attention to the fact that all of these plugins do come at a cost. For some of us the cost is negligible, but for some others the cost means they have to choose between functionality on their blog and making major changes to their hosting and operations. There are probably a lot of things that could be done both by Automattic and by plugin authors that would reduce this cost, but the focus almost always seems to ignore those who can't afford the cost so easily.
I can't say that I see a problem with any particular dofollow plugin causing server strain, but I can see theoretically where it could given enough traffic and enough comments.
Ah, but the plugin is so
Ah, but the plugin is so handy!
[...] favor to me, Dane from
[...] favor to me, Dane from Blog Strokes had provided a detailed tutorial on how to remove nofollow in WordPress without an plugin. I believe that many other bloggers can benefit from his [...]
Andy, I have been using
Andy,
I have been using Lucia's pluging, that is how I came to conclusion that DoFollow (by Kimmo Suominen) is at fault. However, I had SK turned off for about a week and during that week I did not get CPU overload. As soon as I turned the plugin on I get overload. Go figure.
I doubt it is SK unless you
I doubt it is SK unless you are being hit by a tidal wave of spam, and SK is used on 1000s of blogs without major problems.
I suggest you do some testing with Lucia's plugin.
Hard coding changes in the core files isn't an ideal solution, because you have to do the same each time you upgrade.
If you are managing lots of blogs, it is not such a huge problem, especially if you are using tools to manage patching of source code, but that is probably for the geeky programmers out there.
Well Dane I think I was
Well Dane I think I was wrong after all. Today it seams that Spam Karma is causing the problem. I just had to turn it off and rely on math question plugin.
However, this page is well worthed to bookmark and recommend to WordPress bloggers.
fixed ;)
fixed ;)
Hey Dan, I appreciate it. I
Hey Dan,
I appreciate it. I knew you are the right man to ask. And thanks for the link (you should fix it through it goes like this http://htpp://www.....
Thanks again. I will link to this post from my blog as well.
Post new comment