Drupal 6 - How to Remove 'Not Verified' from Anonymous Comments

In this Drupal tutorial, we will look at how to remove the 'Not Verified' which goes next to an anonymous user's name when they post a comment.

To remove 'Not Verified' from anonymous comments in Drupal 6, all you have to do is override an existing function. We do this by editing the "template.php" file (create it if it does not exist) in our theme folder and placing some code inside it. The tutorial below will show you how.

Example 1 - Remove 'Not Verified' from Anonymous Comments

Note that you must replace THEME-NAME-HERE with the name of your theme in the function declaration. Note also the troublesome line that has been commented out to solve the problem:

function THEME-NAME-HERE_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' => 'nofollow')));
    }
    else 
    {
      $output = check_plain($object->name);
    }
 
    //$output .= ' (' . t('not verified') . ')';
  }
  else 
  {
    $output = check_plain(variable_get('anonymous', t('Anonymous')));
  }
 
  return $output;
}

As you can see above, we only need to comment out the line of code which actually adds the "not verified" which we are trying to get rid of.

Example 2 - Shorter way to do the same thing

Added April 28, 2011 - One of our commenters, Raiz, has pointed out that there is an easy way to apply the fix without needing to add all that code. Thanks Raiz!

To perform the fix, all we have to do is add the following to our template file:

function phptemplate_username($object) {
  return str_replace(' ('. t('not verified') .')', '', theme_username($object));
}

What this code does is perform a PHP String Replace on the output of the function to remove the offending text. This way we do not need to hack the code which generates the output in the first place.

It has been tested to work on Drupal 6. So if you know exactly what you are doing, this is a shorter way.

Function overriding is the most common way of modifying the output you receive from Drupal. With knowledge of these principles you are able to customize Drupal to do whatever you want.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...