21
2008
How To Add NoFollow To Your WordPress Post Links
By default, Wordpress adds a "nofollow" property in any anchor link in the comments section, but does not add a nofollow property in the anchor link appearing in the post content.
This hack will basically add a "nofollow" to your Wordpress post links.
Open /wp-includes/post-template.php file and find around line 53 this block of code and add the call to wp_rel_nofollow1() function on line 57 as illustrated below:
53. function the_content($more_link_text = '(more…)', $stripteaser = 0, $more_file = ") {
54. $content = get_the_content($more_link_text, $stripteaser, $more_file);
55. $content = apply_filters('the_content', $content);
56. // this is the hack:
57. $content=wp_rel_nofollow1($content);
58. $content = str_replace(']]>', ']]>', $content);
59. echo $content;
60. }
Then you want to add this function to the file:
function wp_rel_nofollow1( $text ) {
global $wpdb;
$text = preg_replace('|<a (.+?)>|ie', "'<a ' . str_replace(' rel=\"nofollow\"',",stripslashes('$1′)) . ' rel=\"nofollow\">'", $text);
return $text;
}
Keep in mind that this is a hack of the Wordpress core file. If you ever upgrade your Wordpress, then you will need to reapply the hack to the upgraded file.
You may see a working example site that uses this hack:
Enjoy!
RELATED POSTS
WordPress database error: [Can't find FULLTEXT index matching the column list]
SELECT ID, post_title, post_content,MATCH (post_name, post_content) AGAINST ('addnofollow') AS score FROM wp_posts WHERE MATCH (post_name, post_content) AGAINST ('addnofollow') AND post_date <= '2008-08-20 05:02:02' AND (post_status IN ( 'publish', 'static' ) && ID != '16') AND post_password ='' ORDER BY score DESC LIMIT 5


Just add the function to your functions.php file in your theme and you wont have to edit any WP files and when you upgrade it wont be a problem
Good call, Matt. That's another option, too. However, you'll need to give your the_content() function another name, and change that reference in all of your template files.