Site logo

Archived topic

Add datePublished and dateModified to date in metadata with block elements

3 replies · Started by Diogenes on November 12, 2022

Viewing posts 1–4 of 4

Hi.

Create a meta post following the instructions in this video of yours: https://www.youtube.com/watch?v=Ni3KXdZ5Dl8&ab_channel=GeneratePress

I set the publication date to be replaced by the update date, when it is present.

When I check the code I see that the microdata are not added: itemprop="datePublished" and itemprop="dateModified" respectively.

I know there is an option in the Custom Attributes block that allows you to add itemprop.

The problem is that this microdata that I add in Custom Attributes does not discriminate between the date of update and publication, and does not add them directly to the date, but to the block (container).

Is there any possibility of adding this microdata to the publication and update date in the post meta created with block elements, and correctly discriminating them?

I hope I have explained myself correctly.

Hi there,

dynamic data in custom attributes is a really needed feature that we are working on. But its not going to be anytime soon, as it will require some refactoring of how we handle dynamic data.

Today you could use this PHP Snippet to create a shortcode:


function post_modified_date() {
	ob_start();
	echo generate_do_post_meta_item( 'date' );
	return ob_get_clean();
}
add_shortcode( 'modified_date', 'post_modified_date' );

Then in your Headline block you can add: modified_date

And if you use this PHP snippet to filter the dates so the modified is displayed it will apply to that shortcode too:

add_filter( 'generate_post_date_show_updated_only', '__return_true' );

Thanks David, with some adjustments it worked.

Glad to hear that!!

This archived topic is closed to new replies.