
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.

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
And it’s actually that easy
WP should have a variable you could change in the config whether to use nofollow’s or not.
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?
Will this remove text from your post that writes about nofollow, like the code in your post?
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.
Useful post.
@Peter – I believe it will
Maybe it’s better to use some fancy regex for this.
@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/
@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.”
Ah yes, good catch. Not recommended if you’re blogging about nofollow stuff.
really useful
it’s annoying to set dofollow manually, every time you need to change the rel code.
thanks
Very useful to me thanks for sharing
Thanks for the code. Works brilliantly…
Awesome receipe…just loved it…
Trackbacks: