Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor tag within head?

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?

like image 635
Danield Avatar asked Nov 07 '13 08:11

Danield


2 Answers

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.

like image 130
Reeno Avatar answered Nov 01 '22 11:11

Reeno


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.

like image 34
Jukka K. Korpela Avatar answered Nov 01 '22 10:11

Jukka K. Korpela