This has been implemented as a new feature in D8 core: #1184472: Adding rel="author" to "Submitted by" link

How do we do it in D7?

Comments

klonos’s picture

...here's a snippet by bleen18 that's supposed to do the trick:

<?php
function mytheme_preprocess_node(&$variables) {
  $variables['name'] = theme('username', array(
    'account' => $node,
    'link_attributes' => array('rel' => 'author'),
  ));
}

function mytheme_preprocess_username(&$variables) {
   if ($variables['uid'] && $variables['profile_access']) {
     // We are linking to a local user.
    $variables['link_attributes']['title'] = t('View user profile.');
   }
   elseif (!empty($account->homepage)) {
    $variables['link_attributes']['rel'] = 'nofollow';
   }
}
?>

You'll need to place the code in your theme's template.tpl file and change the mytheme part of the functions to the actual name of your theme.

klonos’s picture

I have tried adjusting and adding the code to core's Garland theme, but I can't get it to work :?

modctek’s picture

I tried this code as well, but it changed my byline to "Anonymous". Might be interference from the theme itself...haven't looked at the code to determine. This is the "Titan" theme.

mntash’s picture

I am very interested in getting this to work.

I had created a forum post here: http://drupal.org/node/1515288 trying to figure out how to do it.

I don't know if this should be added to core, because rel=author is only supported by google, right?

But anyways, I would love to know how to add a rel=author link for each node which points to the user's profile. And from there, would need a rel=me pointing to their social networking profile, such as G+

klonos’s picture

...because rel=author is only supported by google, right?

Well, I believe that everyone agrees that Google is very important when it comes to SEO, and this problem needs to be addressed. I don't know if core is the right place to do it (it was done in core for D8 though - see issue summary above) or if it should be handled in contrib. I simply need to solve this.

BTW, I realize that the issue at hand is not UI related, but nevertheless I'd like to point to: #1505456: Add a "Backports" or "Drupal update" module to Drupal 7 core so that UI changes from Drupal 8 can be backported

mntash’s picture

Thanks for the reply.
Yes, Google is the most important search engine right now, and that's why I am looking for a solution for rel=me and rel=author. I guess my concern is more of a generic "what if Bing comes out with their own markup, or Google becomes less relevant in the future?"

But no matter, because right now I need rel=me and rel=author. I read on another site that wordpress has it already or will very soon. I will keep an eye on the thread you linked to regarding backports. I just need this to work, soon.

mntash’s picture

I'm pretty much over my head with this one. I posted a request for help here: http://drupal.org/node/1515288 but not replies yet.

What I thought I could do is to add a profile text field where users could add the URL to their Google+ page in their user profile in Drupal. Then I could somehow insert a rel=me link directly into the header of the node. That should bypass the rel=author step.

Or, use the full 3 step process: rel=author in the node, rel=me in the user profile/author page, and the reciprocal link from G+ profile to user profile/author page in Drupal.

There's no way to add an extra link in a node using Meta Tag module? Or maybe add a field in structure/content type?

mntash’s picture

bump

jamix’s picture

Status: Active » Needs review

template_preprocess_username() in D7's core overwrites $variables['link_attributes'] passed to it. We can add the extra rel attribute ourselves based on a flag set in mytheme_preprocess_node().

This works in Drupal 7.10 (I should upgrade, I know, I know):

function mytheme_preprocess_node(&$variables) {
  $variables['name'] = theme('username', array(
    'account' => $variables['node'],
    'authorship' => TRUE,
  ));
}

function mytheme_preprocess_username(&$variables) {
  if (!empty($variables['authorship'])) {
    $variables['link_attributes']['rel'][] = 'author';
  }
}

As usual, replace mytheme with your theme name, put the code in your template.php and clear cache.

mntash’s picture

Thanks. So this links the node to the node author's page on the website.. and the author's page should then be linked to the author's G+ or other social account?

doru’s picture

I searched everywhere for the above for Drupal 6. I haven't found it.
I am using Drupal 6 with a Genesis child theme. I am not versed enough to modify this for D6.

Cheers,

remkovdz’s picture

Is there already a good solution for this?

Pasqualle’s picture

Status: Needs review » Closed (fixed)