11

I want my website to become eligible for Google+ Direct Connect.

So after googling a bit I found this Google Support page, which has since been edited.
View Google Support page providing these instructions via WayBack Machine:

You can directly link your website by inserting a small snippet of code on your website and then listing that website as your Google+ page's primary link in the About section of the profile. For example, if your Google+ page’s primary link is set to www.pagewebsite.com, you can create a bidrectional link by placing the following code snippet in the <head> tag of the site’s HTML:

<a href="https://plus.google.com/{+PageId}" rel="publisher" />

What gives? An anchor tag within the head?

I thought only title/meta/link tags are allowed in the head.

Is it legal to place that above snippet in the head tag?

albert
  • 8,112
  • 3
  • 47
  • 63
Danield
  • 121,619
  • 37
  • 226
  • 255

3 Answers3

17

I think there's an error in Google's documentation and this should be a <link>-tag, like this:

<link href="https://plus.google.com/{+PageId}" rel="publisher" />

You can test it on https://developers.google.com/structured-data/testing-tool/ if it works. Include the <link>-tag into your website and see what Google detects with this tool. There's a section "Publisher" where you can see if Google detects the correct information.

I'm using <link> on my sites and Google detects the correct values.

Reeno
  • 5,720
  • 11
  • 37
  • 50
1

An a element inside head is of course invalid according to any HTML specification. I have no idea why Google tells you to do so, but presumably their software actually looks for such tags.

What happens in practice in browsers is that the a tag implicitly closes the head element (you can see this if you look at the document tree in Developer Tools in a browser). This isn’t as bad as it sounds, since the rest of elements meant to be in the head will still be processed normally. For example, even a title element works when placed inside body. To tell truth, the division of a document into head and body is just a formality.

The tag <a href="https://plus.google.com/{+PageId}" rel="publisher" /> will be taken as a start tag only, potentially causing naughty surprises, since the start of the document will then be inside a link (which might extend to the end of the document!). Only if the page were served with an XML content type would the tag be taken as “self-closing”. So if you have been forced into using such an element, at least write it with a real end tag;

<a href="https://plus.google.com/{+PageId}" rel="publisher"></a>

It will still be bad for accessibility and usability, since empty links may still participate in tabbing order etc.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
0

Using link tag is the right (and valid!) way to go in the header:

<link href="https://plus.google.com/{+PageId}" rel="publisher" />

If you stick with the verbatim anchor tag when following the instructions (Link your brand page to your website), then you'll be setting yourself up for something to blow up down the road.

We just experienced it, in fact. It seems starting with iOS 8.x, mobile Safari will see this anchor tag and move it (along with the code below it!) to the body. This broke a smart banner we had in place.

We switched to using a link tag and verified that Google still detects the correct values.

Steven Silvey
  • 51
  • 1
  • 3