WordPress google structured data hentry markup errors

WordPress Google Structured Data hentry Markup Errors

In this post I will show how to fix Google Structured Data hentry Markup Errors by adding some code to the functions.php file of WordPress.
As always you should make any changes to your WordPress using a child-theme.
This solution will still work even if you are not using a child-theme. The down side of not using a child-theme is the fix will be lost after any theme update and will have to be re-applied.
You can find the functions.php file you need to edit probably inside //root/wp-content/themes/child-theme/.
Add this bit of code at the end of the file.
It is recommended to insert the lines right after the last function found in functions.php or just above the ?> mark.
Some themes do not have the php closing tag ?> in functions.php. If this is the case, just insert the lines at the bottom if the file.
Note: you will need to change the date_default_timezone_set (‘America/Chicago’)
to whatever applies to your use. In the example below it is set for ‘America/Chicago’ or US Central timezone.
A list of Timezone codes can be found here PHP list of supported Timezones.

Code to fix WordPress Google Structured Data hentry Markup Errors

Add the code below to the functions.php file.

//Add hatom data structure

function add_hatom_data_structure($content) {
date_default_timezone_set('America/Chicago');
$t = get_the_modified_time('c');
$author = get_the_author();
$title = get_the_title();
$pt= get_the_date('c');
if (is_home() || is_front_page() || is_singular() || is_page() || is_archive() || is_category() ) {
$content .= '<div class="hatom-extra" style="display:none;visibility:hidden;"><span class="entry-title">'.$title.'</span> is published on <span class="published">'.$pt.'</span> and 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_hatom_data_structure');

That should do it. You have now fixed WordPress Google Structured Data hentry Markup Errors. You can go to the Google Structured Data Testing Tool and check to see if the hatom/hentry entries appear correctly by running a live check.
Hope this helps if you are having WordPress Google Structured Data hentry Markup Errors.

Visit the Zeros Ones YouTube channel.



Leave a Reply

Your email address will not be published. Required fields are marked *