Wordpress Hack » Inserting rel nofollow on links in all categories…

I wanted to add rel='external nofollow' onto every Link in every Category that didn't have an explicit rel attribute defined. I looked though the Wordpress Codex but found no Plugin Hooks to do it so I broke out the source code.

Somewhere down the chain the link markup "<a ..." is generated in the function get_links() found in /wp-include/links.php (approx line 142). I added two lines of code shown below and it works a treat.

Before

PHP:
  1. $rel = $row->link_rel;
  2.        
  3. if ($rel != '') {
  4.     $rel = " rel='$rel'";
  5. }

After

PHP:
  1. $rel = $row->link_rel;
  2.        
  3. if ($rel != '') {
  4.     $rel = " rel='$rel'";
  5. } else {
  6.     $rel = " rel='external nofollow'";
  7. }