Archived topic
Use Page Hero and keep datemodified and datepublished
11 replies · Started by Matt on April 13, 2022
When using the page hero it removes these from the HTML
itemprop="dateModified">April 9, 2022
itemprop="datePublished">April 7, 2022
Is there a way to keep this in the html?
Here is an example post that has it removed
Hi there,
any particular reason you want to keep both dates in the HTML?
As in the Head of your site you have meta properties that define both dates:
https://www.screencast.com/t/b58qAE8n
So any bot wanting to get the published and updated date can do so
Let me know
It's a recommendation by google to specify datePublished and or dateModified structured data.
https://developers.google.com/search/docs/advanced/appearance/publication-dates
The default post meta includes this but when I use the page hero both are removed.
My interpretation of that and from a lot of feedback we get, its best to only output the HTML for one date, and that should be the date you want the user to see
ie. Add a user-visible date to the page and feature it prominently.
If you have both dates in the HTML then its best that they are both displayed to the user.
The need for both datePublished and dateModified is within the Structured Data (JSON-LD), which it looks like your SEO plugin can add for you:
https://kb.theseoframework.com/kb/structured-data-supported-by-the-seo-framework/
In the absence of the Structured Data (JSON-LD) the bot will use the schema meta you already have as shown in the screenshot above.
But of course if you want both in the HTML, the you would need to use a Shortcode in place of the Dynamic Data.
1. Add this PHP Snippet to your site:
add_shortcode( 'db_post_date', function() {
ob_start();
echo '<div class="entry-meta">';
generate_do_post_meta_item( 'date' );
echo '</div>';
return ob_get_clean();
} );
How to add PHP: https://docs.generatepress.com/article/adding-php/
2. Edit your Element, and replace the Dynamic data in the date headline with the shortcode: [db_post_date]
The before text you can include in the same headline block as the shortcode eg.
Latest date: [db_post_date]
Thanks. Looks like that added it back.
Can you help with the style? The shortcode is in the same container as the author info but its margins seem off.
SCRAP THIS!!
Done. But it's still not aligned.
Sorry ignore that change to the shortcode, we need the wrapper to hide some of the HTML.
Can you return to as was:
https://generatepress.com/forums/topic/use-page-hero-and-keep-datemodified-and-datepublished/#post-2187329
Yes I have returned the shortcode.
Add this CSS:
.inline-post-meta-area .entry-meta {
margin-top: 0;
font-size: 1em;
line-height: inherit;
color: inherit;
}
For the pipe divider - if you use a Headline Block for it, you can then remove the Bottom Margin from it in the spacing settings.
Got it. Thanks for the fast support!!
You're welcome