Friday, November 18, 2011

Workaround: Link to Google+ Page HTML5 valid [rel=publisher]

Google+ Pages
Google recently introduced the Google+ brand pages. Pages include a reciprocal linking feature. What does this mean? Well, first you'll have to set up your brand page, next you'll have to add a tiny line of code to the head-section of your site.

However this line of code is currently not a standard-HTML5-markup, therefore the W3-validator will return an error. After a few weeks of thinking I found a solution - which is more a quick workaround than a real solution - however it should be enough for now.

Read how to solve this problem after the break...

Link to Google+ page with your website in a HTML5-valid way:

  • Create a Google+ page (if not done so far).
  • First of all grab the tiny piece of code from Google+ badge config tool. Make sure you use your the right page-id (you can find it in the canonical tag on your Google+ page).
  • You'll just need the first line of code, which should look like: <link href="https://plus.google.com/YOUR_PAGE_ID" rel="publisher" />
  • Open your favorite HTML-editor and go to the head-tag.
  • Now check for the PHP-variable $_SERVER['HTTP_USER_AGENT'] W3-validtor and tell the script to show the link-tag only if the user-agent does not contain W3C_Validator
The result should look somewhat like this:

if(substr($_SERVER['HTTP_USER_AGENT'], 0, 13) != 'W3C_Validator'){ echo '<link href="https://plus.google.com/YOUR_SITE_ID/" rel="publisher" />'; }
Now go ahead, check the linking with the Google rich snippets tool and validate your code:

I hope you'll enjoy this quick fix. Let's hope the rel=publisher tag may become a valid attribute again.

0 comments:

Post a Comment