Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Last active February 14, 2019 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imelgrat/977c8cd2e5594f24ab6aea88375fc583 to your computer and use it in GitHub Desktop.
Save imelgrat/977c8cd2e5594f24ab6aea88375fc583 to your computer and use it in GitHub Desktop.
Adds hidden hatom tags to WordPress posts after the content block. They're not visible to humans but parsers will still see and parse them
<?php
/**
* Adds hidden hatom tags to WordPress posts after the content block.
* They're not visible to humans but parsers will still see and parse them.
*
* @link https://imelgrat.me/wordpress/hentry-fix-errors-wordpress/
*
* @param string The post content
*/
function add_hatom_tags($content)
{
if (is_home() || is_singular() || is_archive() ) {
$content .= '<div class="hatom-extra" style="display:none;visibility:hidden;"><span class="entry-title">'.get_the_title().'</span> was last modified: <span class="updated"> '.get_the_modified_time('F jS, Y').'</span> by <span class="author vcard"><span class="fn">'.get_the_author().'</span></span></div>';
}
return $content;
}
add_filter('the_content', 'add_hatom_tags');
// This filter adds the entry-content hAtom tag, showing where the full content block is.
function add_hatom_post_content ($content) {
if ( in_the_loop() && !is_page() ) {
$content = '<span class="entry-content">'.$content.'</span>';
}
return $content;
}
add_filter( 'the_content', 'add_hatom_post_content');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment