Post Pic

How to automatically remove the Nofollow from your posts

By default, WordPress automatically converts all links from the post content to nofollow. If you prefer your links to be dofollow, just read and use the following recipe.

Copy the following code, and paste it on the functions.php file from your theme. Once you saved the file file, the rel="nofollow" attributes will be removed.

function remove_nofollow($string) {
	$string = str_ireplace(' rel="nofollow"', '', $string);
	return $string;
}
add_filter('the_content', 'remove_nofollow');

Thanks to Jeff Starr for this awesome piece of code. Have you checked out the book Jeff wrote with Chris Coyier? It's called Digging into WordPress and it is great!

14 Responses

Feb 03 2010 10:52

And it’s actually that easy :)
WP should have a variable you could change in the config whether to use nofollow’s or not.

Feb 03 2010 15:02

I had a quick look on my WordPress install and didn’t see any nofollow links.
Maybe its because I am still on 2.8?

Feb 03 2010 15:29

Will this remove text from your post that writes about nofollow, like the code in your post?

Feb 03 2010 17:08

Pretty sure this statement is untrue: “By default, WordPress automatically converts all links from the post content to nofollow”.

Comments, yes. Posts, no. Perhaps you’re using a plugin that makes your post links nofollow, but default WP doesn’t do that.

Feb 03 2010 17:18

Useful post.

Feb 03 2010 18:27

@Peter – I believe it will :) Maybe it’s better to use some fancy regex for this.

Feb 03 2010 21:39

@Andrew: WordPress automatically adds “nofollow” attributes to comment links and comment-author links, but does not add them to post content. To remove nofollow from comments, add this line of code to the function:

add_filter(‘comment_text’, ‘remove_nofollow’);

@Peter: this code will remove only the actual “nofollow” attribute from the (X)HTML source code output, so no changes made to any other content. Plus, as a filter, the function does not change anything in the database. More information at: http://digwp.com/2010/02/remove-nofollow-attributes-from-post-content/

Feb 03 2010 21:56

@Jeff The problem I thought this code could have, is mentioned in the blog post you mentioned in your comment.

It says: “Note that if you have some posts about nofollow, this function will remove rel=”nofollow” from your code examples as well.”

Feb 03 2010 22:07

Ah yes, good catch. Not recommended if you’re blogging about nofollow stuff.

Feb 07 2010 09:55

really useful
it’s annoying to set dofollow manually, every time you need to change the rel code.
thanks

Feb 08 2010 06:45

Very useful to me thanks for sharing

Feb 10 2010 17:09

Thanks for the code. Works brilliantly…

Mar 03 2010 11:11

Awesome receipe…just loved it…

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required