7

In the brave new world of Google, great integration with Google+ is mandatory for all webmasters who want to get as much traffic as possible. If adding the rel="publisher" attribute to a website is done with the Meta Tags module, it seems that there's no official way for supporting the rel="author" attribute. For those of you who don't know about I am talking about, read this article from Google: Author information in search results

Apparently support will be included in Drupal 8. I've seen some discussions about adding this to the Drupal 8 core.

But how to implement this in Drupal 7?

I am asking this as a noob in customizing the insides of Drupal. So, if you have some good ideas, please keep this in mind.

Appreciate your ideas.

8

The rel=author property is now supported by the Drupal 7 Metatags module dev version.

After installing the metatags module (http://drupal.org/project/metatag), go to admin/config/search/metatags, and edit the front-page or one of the node pages. Under 'Advanced' you will see the author and publisher fields where you can input your google+ page URL. On the following screenshot, I've marked the places you need to change the configuration in pink.

Metatags frontpage configuration page:

Here is my screenshot - configuration is marked in pink

  • Thanks for pointing this out, way less complicated to make a token and have people input it this way. – Stephen P. Mar 25 '13 at 14:28
5

Using ideas from the rdf_preprocess_node() function that Dave Hall linked you could implement it this way (code goes into your theme's template.php file):

function mytheme_preprocess_node(&$variables) {
  if ($variables['page']) {
    $account = user_load($variables['uid']);
    $title = $account->name;

    $author_info = array(
      '#tag' => 'link',
      '#attributes' => array(
        'rel' => 'author',
        'href' => 'http://localhost',
        'title' => $title,
      ),
    );

    drupal_add_html_head($author_info, 'author');
  }
}

This adds the necessary link into the head section of full node pages. I used the node author's id to get the necessary user data. You'd probably want to add a website field for users that you could use here to get a complete solution.

  • So, i should add a field for each user where the Google+ Profile link information is stored? Also, sorry for my ignorance here - is there a specific name I should give to that field? – Corporate Geek Jan 22 '12 at 19:47
  • @CorporateGeek Yeah I think that would be a good approach and the field name doesn't really matter. The Profile2 module seems to be suitable for the field addition. I might be off here, but you could probably use $page = $account->field_myfieldname['und'][0]['value']; to get the value later in the code to add it to the 'href' attribute. – Madis Jan 22 '12 at 23:11
  • There is actually no need for the Profile2 module in Drupal 7 as field support for users comes with core already (admin/config/people/accounts/fields). – Madis Jan 23 '12 at 22:52
  • This is an excellent approach. The only thing I changed was to use if ($node = menu_get_object()) { if($node->type == "blog") { ... to test for my blog content type. Thanks! I also like the idea of adding a field for the G+ URL if there's more than one user on a site, that way it's fully dynamic. – Danny Englander Aug 5 '13 at 22:17
4

Implementing hook_preprocess_node() in a module or your theme should do it. Check out the rdf module's implementation for some inspiration. http://api.drupal.org/api/drupal/modules--rdf--rdf.module/function/rdf_preprocess_node/7

  • 1
    Is it possible to provide a bit more guidance, for the folks who are not really technical? – Corporate Geek Jan 14 '12 at 10:21
1

I know I'm late to the party, but I'm answering this for people who land on this page in search of a solution.

There is now a Google Authorship module.

0
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';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.