Add rel author to user names in Drupal 7

Adding rel=author to your usernames to support the Google authorship feature is a snap!

<?php
function themename_preprocess_username(&$vars) {
 
// Username is linked, use the link_attributes to inject the rel attribute
 
if (isset($vars['link_path'])) {
   
$vars['link_attributes']['rel'][] = 'author';
  }
 
// Username is NOT linked, use the attributes_array to inject the rel attribute
 
else {
   
$vars['attributes_array']['rel'][] = 'author';
  }
}
?>

Last updated 16th June, 2012 - 1:32pm

Authored by Jeff Burnz on