Adding the nofollow attribute to user-defined links

Why

When Google wants to find out how to rank a search result, one of the most important factors it looks at is how many other links the website has. The more links from high-quality websites a site has, the higher it will be ranked. This is the mechanism that spammers try to abuse by posting their URL on your forums.

The solution

To solve this problem, Google has invented the so-called nofollow attribute. By adding rel="nofollow" to user-defined links (<a href="(...)" rel="nofollow">(...)</a>), you let Google know that this link does not come from a trusted source and should be ignored when ranking the website behind it.

Modding your IPB

In order to add the nofollow attribute to all user-defined links, you will have to edit two files:

class_bbcode_core.php
  1. Open the file "sources/classes/bbcode/class_bbcode_core.php"
  2. Search for the following line (should be around #2220):
    return ( isset($url['st']) ? $url['st'] : '' ) . "<a href=\"".$url['html']."\" target=\"_blank\">".$show."</a>" . $url['end'];
  3. And replace it with these three lines - the second line makes sure that the attribute is only added to outgoing links:
    //hbtronix.de/IPB - nofollow
    $nk_add_nofollow = !(substr($url['html'], 0, strlen($this->ipsclass->vars['board_url'])) == $this->ipsclass->vars['board_url']);
    return ( isset($url['st']) ? $url['st'] : '' ) . "<a href=\"".$url['html']."\" target=\"_blank\"" . ($nk_add_nofollow? " rel=\"nofollow\"" : "") . ">".$show."</a>" . $url['end'];
  4. Save and upload the file
profile.php
  1. Open the file "sources/action_public/profile.php"
  2. Search for the following line (should be around #284):
    $info['website'] = $member['website'] ? "<a href='{$member['website']}' target='_blank'>{$member['website']}</a>" : $this->ipsclass->lang['no_info'];
  3. And replace it with these two lines:
    //hbtronix.de/IPB - nofollow
    $info['website'] = $member['website'] ? "<a href='{$member['website']}' target='_blank' rel='nofollow'>{$member['website']}</a>" : $this->ipsclass->lang['no_info'];
  4. Search for the following line (should be #749):
    $info['homepage'] = "<a href='{$member['website']}' target='_blank'>{$member['website']}</a>";
  5. And replace it with these two lines:
    //hbtronix.de/IPB - nofollow
    $info['homepage'] = "<a href='{$member['website']}' target='_blank' rel='nofollow'>{$member['website']}</a>";
  6. Save and upload the file

Testing

Check the user profile and the parsing of bbcode in posts to see if there are any errors. If you look into the source code of the pages, you should see a 'rel' attribute in all user-defined links. If you have any problems, feel free to contact me!

Credit

If you liked my modifications, please link back to this site (http://hbtronix.de/IPB/)!

Last updated

This site was last updated 2008-03-29.