WordPress 4.1.1 hAtom microformat hentry fix

Symptoms
WordPress 4.1.1 + custom template.
Google Webmaster Tools > Structured Data > hentry ERROR
Missing: entry-title
Missing: updated

Cause
The use of CSS class “hentry” in custom WordPress templates requires additional CSS class tags to reflect author, title, date updated, etc.

Solution
Add the following code to the bottom of functions.php:

//mod content
function hatom_mod_post_content ($content) {
  if ( in_the_loop() && !is_page() ) {
    $content = '<span class="entry-content">'.$content.'</span>';
  }
  return $content;
}
add_filter( 'the_content', 'hatom_mod_post_content');

//add hatom data
function add_mod_hatom_data($content) {
    $t = get_the_modified_time('F jS, Y');
    $author = get_the_author();
    $title = get_the_title();
    if (is_home() || is_singular() || is_archive() ) {
        $content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
    }
    return $content;
    }
add_filter('the_content', 'add_mod_hatom_data');

Any post in your WordPress web site will now look like this:

<article id="post-358" class="post-358 post type-post status-publish format-standard hentry category-partners">
<header><
  <div class="post-entry">
    <span class="entry-content">
    <p>Article content here</p>
    </span>
    <div class="hatom-extra">
      <span class="entry-title">Article title here</span>
      was last modified: 
      <span class="updated"> March 31st, 2015</span>
      by
      <span class="author vcard">
        <span class="fn">Tablelands Computers</span>
      </span>
    </div>
  </div>
  <footer class="post-data">...</footer>
  <div class="post-edit">...</div>
</article>
 
WordPress 4.1.1 hAtom microformat hentry fix was last modified: May 26th, 2015 by tabcom