You are here

Home » Blogs » Konstantin Boyandin's blog

I suppose every blog owner knows what "dofollow' is. Since I switch all my blogs to this mode, I suppose I will post a quick how-to on enabling this mode for Drupal right here, in my blog.

Drupal themes use "nofollow" mode by default. To switch the mode, you should (re)define themeid_username() function in template.php file (the file should be located in the root directory of a theme you wish to transform into "do follow" mode. If such a file doesn't exist, simply create it and assign proper permissions.

If you're unsure what theme you are using, proceed to «Administer» -> «Site building» -> «Themes» or look into a site's page source, theme is often mentioned there.

Navigate through the site's file system to a directory (folder) named themes/themeid, where themeid is the current theme's identifier. It is case-sensitive and may be found in the .info file located in the theme's root directory.

Once again: if there's no template.php in the theme's root, just create it (don't forget to add <?php in the very beginning). Now copy (paste) the code similar to this one:

function themeid_username($object) {

  if ($object->uid && $object->name) {
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    else {
      $name = $object->name;

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array(
        'attributes' => array('title' => t('View user profile.'))
    else {
      $output = check_plain($name);
  else if ($object->name) {
    if (!empty($object->homepage)) {
      $output = l($object->name, $object->homepage, array(
        'attributes' => array(
          'rel' => 'external')
    else {
      $output = check_plain($object->name);

    // $output .= ' ('. t('not verified') .')';
  else {
    $output = variable_get('anonymous', t('Anonymous'));

  return $output;
Don't forget to use the actual themeid string (highlighted in the code above).

Note: where 'external' is mentioned in the code above, Drupal core did put 'nofollow'. I.e., all comments links will now be marked with rel="external" attribute. If you don't like it either, comment out or erase the string containing 'external' in the code above. Note that the code present is originally taken from Drupal 6 core and it only re-defines the way links are treated. In other words, this is valid Drupal way to handle links.

After you have added the code above, make sure that the resulting PHP file is valid, i.e. by running a command

$ php -l template.php
otherwise the site may become inaccessible. After the file has been saved, purge the themes cache by purging cache at «Administer» -> «Site configuration» -> «Performance» (in case you use Drupal built-in cache).

That's all, DoFollow is now enabled for this theme. Please note: if you plan to update theme files and if theme contains template.php, make sure you apply the change above to the new theme files, otherwise your DoFollow status will vanish.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

User login