10 Apr 2012

WordPress Complicates Google Authorship Markup (But It Can Be Done)

Back a couple of months ago, I wrote a post For Internet Marketing Ninjas detailing how to set up Google authorship markup on your website. I’ve been writing about this topic since last summer, just after it was first announced, and I swear Google’s been running serpentine trail on this the whole time. It’s as if every time I go back and look at Google’s documentation on the topic, they’ve changed it yet again. I suppose that’s not surprising, as the original efforts to define the process were either written by engineers or were never passed through a usability review. The instructions, not to mention the implementation processes, were cumbersome at best, so updates are not surprising (although that doesn’t really explain why they have multiple docs published that in some implementation aspects contradict each other! Argh!). I suppose in the end, it’s good they are responding to customer frustration over the poorly conceived process, but it’s not been pretty.

One particular area of frustration, and this cannot be laid at the feet of Google, is getting authorship markup to work in WordPress. This is more of a failure of WordPress to allow non-developer-users simple access to the technical underpinnings of its architecture (and don’t argue that it’s easy PHP edits – sorry, but poorly documented platforms that bury site functionality among a host of files is not easy to edit).

Luckily, intrepid WordPress experts who know how to write have blazed a solution trail for the rest of us. I’m going to share here my experiences in getting a WordPress site up and running with Google authorship markup.


Conceptual overview

In my previous Ninja post on authorship markup, I defined a circuit of links that Google needs to see to verify content authorship.

  1. A Google+ profile for the author that links to the content site, either to an author biography page (or to the home page of the site when there is no author biography page)
  2. An author biography page that links to the Google+ profile page using the anchor text “Google+”. The anchor tag must include the tag attribute rel=”me”.
  3. All content pages link to the author biography page (or when no such page exists, to the Google+ profile page) preferably using the author’s name as anchor text. The anchor tag must include the tag attribute rel=”author”.

Of course, there’s a lot of caveats to all this. In the latest update to the authorship markup docs, Google has enabled a new variation of Step 3 to be the use of the author’s email account, which must also be included (and verified) in the Google+ profile (but the mailto:-linked author name must be preceded by the word “By”). I’ve also seen now many variations on what is required as anchor text, such as that the + symbol can actually be at the start OR the end of the anchor text of the tag using rel=me, and the anchor text doesn’t necessarily need to be “Google”. Furthermore, apparently you can also use a g+ image (supplied by Google) as the rel=author link. I also understand that the Google+ profile must include a headshot photo, nothing else.


Tricks for WordPress sites

The big challenge for WordPress site owners is that WordPress by default doesn’t allow for anchor tags to use the rel= attributes needed for Google authorship markup. Luckily there are workarounds available.

For simplicity’s sake, there are several new WordPress plugins available (and the number keeps growing) that enable the functionality needed. These are simple to implement and don’t require editing PHP source code. But be warned – apparently many of these plugins enable all sorts of new, open functionality that, in cases of external or untrusted authors, could expose the site (and its readers) to all sorts of security risks. Yikes! If you go this route, be sure to study up on the risks involved in how the specific plugin works before implementing it in the site code.

Alternatively, there are source-code-editing solutions at hand as well. If you have access to the site source code, here is a relatively painless way to enable the site functionality needed for authorship markup, broken out by single-author and multi-author blogs.

For single-author blogs

To apply the rel=author anchor tag attribute needed in links from your content pages to your author biography page, follow these steps:

Add rel=author functionality

  1. Log in to the WordPress site.
  2. From the Dashboard, click Appearance, click Menus, and then click Screen Options.
  3. Select the Link Relationship (XFN) checkbox.
  4. Click the down-pointing arrow on the right of the menu item containing the author biography, typically listed as About <author name>.
  5. In the text box labeled Link Relationship (XFN), type author, and then click Save Menu.

The page linked in menu item About <author name> will serve as the official author biography page.

Add rel=me functionality

To implement the rel=me anchor tag attribute in the link from the author biography page to the Google+ profile page is a bit trickier. To do so, you modify two of the site’s PHP files with new source code.

One of the most popular code-based solutions comes from the blog Yoast.com in a post titled, rel=”author” and rel=”me” in WP and other platforms. Feel free to read Joost de Valk’s excellent post, but the gist of what you need to do is as follows. These code edits will automatically generate a link on the author biography page to the author’s Google+ profile using the rel=me attribute.

Before editing source code files, we strongly recommend that make copies of the original files and place them in your site’s child theme directory (this way you don’t lose your customized changes the next time WordPress or your theme’s publisher updates the original source code files). The source location for the original files will be in your theme directory, /wp-content/themes/<YourTheme>. Here’s the procedure for the changes needed:

  1. Create a copy of the file functions.php in your WordPress theme directory named functions.php.old, and then copy functions.php into your WordPress child theme directory.
  2. Open the file functions.php for editing from the WordPress child theme directory in a text editor, such as Windows Notepad.
  3. Copy and paste the following custom function code after the opening <?php tag in the file:
    // Enable WordPress to allow rel=”me” in Google+ profile link
    function yoast_allow_rel() {
      global $allowedtags;
      $allowedtags['a']['rel'] = array ();
    }
    add_action( 'wp_loaded', 'yoast_allow_rel' );

    // Add Google Profile field to WordPress User Profile
    function yoast_add_google_profile( $contactmethods ) {
      $contactmethods['google_profile'] = 'Google Profile URL';
      return $contactmethods;
    }
    add_filter( 'user_contactmethods', 'yoast_add_google_profile', 10, 1);
  4. Save and close the file.
  5. Create a copy of the file author.php in your WordPress theme directory named author.php.old, and then copy author.php into your WordPress child theme directory.
  6. Open the file author.php for editing from the WordPress child theme directory.
  7. Copy and paste the following custom function code within the last <?php tag in the file:
    // Output new Google profile URL with rel=me attribute added
    $google_profile = get_the_author_meta( 'google_profile' );
      if ( $google_profile ) {
        echo '<a href="' . esc_url($google_profile) . '" rel="me">Google+</a>';
    }

    Note: You may need to experiment with the exact location of this code snippet within the file so that the Google+ link appears in an aesthetically acceptable location on the page.

  8. Save and close the file.
  9. Use FTP to copy the edited functions.php and author.php files onto the web server in the child theme directory.
  10. From the Dashboard, click Users, and then click Your Profile (you may need to refresh the page).
  11. Scroll down to the section Contact Info, find the field Google Profile URL, and then type or paste the URL to the Google+ profile.
  12. Click Update Profile.

Notes:

  • The official author biography page in this solution will typically be the in the /author/<AuthorName> directory.
  • Be sure to test the functionality of your site’s pages once this new code has been uploaded. Due to the large variety of WordPress themes, code compatibility could be an issue. If pages, such as content pages or the author biography page, fail to load properly, delete the revised files, revert the renamed files back to their original names, and use FTP to upload the original code files back to the website to restore functionality.

For multi-author blogs

Many WordPress themes allow authors to enable the biography content from their WordPress User Profile to appear at the bottom of each post. For themes that don’t support this feature, site administrators can install the WordPress plugin WP Biographia to add this functionality. By adding biographical information to each post, a specific author biography page is not needed. To make this configuration work with Google authorship markup, follow these steps:

  1. Log in to the WordPress site.
  2. From the Dashboard, click Users, and then click Your Profile.
  3. Scroll down to the About Yourself section. In the Biographical Info box, add a few brief lines of text for your online biography, then add a new line at the bottom containing a link using the format of this sample code:
    <a href="https://plus.google.com/<YourGoogleProfileID>?rel=author">Google+</a>

    Note: You’ll need to return to the Google+ profile page and copy the profile ID number within the URL for your link.

  4. Because no author biography page is used in this configuration, you need to change the way the Google+ profile connects back to this author’s content. Browse to the Google+ profile page, log in, and then click Edit Profile.
  5. Click the section labeled Contributor to.
  6. Click Add custom link.
  7. The top text box is the author page link label. Create a label using the format “<Company name>: <persona name>” as in “Spiffy Movers: John Doe” (do not add quotes) to type the label.

    Note: The style referenced above is merely a format suggestion. There is no required writing style for the label.

  8. Type (or paste) the URL of home page on your website, and then click Save.
  9. Click Done editing when finished revising the profile.

Note: The official author biography page in this solution will typically be the in the /author/<AuthorName> directory.


Verify your work

As mentioned in my previous Google authorship markup post, be sure to test your site modifications with the Google Rich Snippets Testing Tool. Test both a content page URL and the author biography page URL (if used). This is the test result you are looking for:

Extracted Author/Publisher for this page

author
  linked author profile = <URL to author biography page, if used, or a link to the Google+ profile page>
  google profile = <URL to Google+ profile page>
  author name = <Persona author name>
  Verified: Authorship markup is verified for this page.

Any results with red text means something’s not configured right. Carefully review the steps above to debug the work.


Final caveat

Even if you get everything all set up correctly, all of the anchor tags use the proper attributes and the Google+ profile is up and running, there’s no guarantee that Google will use the authorship markup data you’ve provided for your articles to show your photo next to your content in their search engine results pages (SERPs). That last part, the biggest part of the puzzle, is left to their subjective decision-making process. That said, there’s no reason NOT to go through this process if you publish high quality content on a regular basis, especially if it’s usually focused on a particular subject. Google wants high-quality content, and they want to recognize it. Do the work, confirm it’s technically valid using their testing tool, and then be patient. Good things come to those who wait.