How to add user role as a class while rendering a username I'd like to style the username of certain roles differently (mainly admin roles) and I think the way to do it is to append the user roles in the class of the username.

I'd like your help with this because I've tried this but it doesn't work:

function THEME_username(&amp;$vars) {
  foreach($vars['user']-&gt;roles as $role){
    $vars['classes_array'][] = 'role-' . drupal_html_class($role);
  }
}
You need to preprocess the theme function, and add to the attributes array or link options, depending on context. Currently you're overriding the theme function and reducing its output to an empty string.

function MYTHEME_preprocess_username(&amp;$vars) {
  foreach($vars['account']-&gt;roles as $role) {
    if (isset($variables['link_path'])) {
      $vars['link_options']['attributes']['class'][] = 'role-' . drupal_html_class($role);
    }
    else {
      $vars['attributes_array']['class'][] = 'role-' . drupal_html_class($role);
    }
  }
}