Site logo

Archived topic

How can remove dataPublished markup?

11 replies · Started by Luong on March 13, 2019

Viewing posts 1–12 of 12

I want to remove dataPublished markup from the posts so Google can only read dateModified.

Please help me!

Hi there,

Give this function a try:

add_filter( 'generate_post_date_output', function( $output, $time_string ) {
	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';

	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
		$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%4$s</time>';
	}

	$time_string = sprintf( $time_string,
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() ),
		esc_attr( get_the_modified_date( 'c' ) ),
		esc_html( get_the_modified_date() )
	);

	return sprintf( '<span class="posted-on">%s</span> ', // WPCS: XSS ok, sanitization ok.
		$time_string
	);
}, 10, 2 );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Let me know :)

Hi,
I added the code in the functions.php of the child theme. But when I checked with Google's structured data testing tool, it still showed the datePublished.

Can you link me to page you're testing?

here's the link to one of the posts:

The code I mentioned above doesn't seem to be activated. If it is, you might have another conflicting function. Anything else targeting the generate_post_date_output filter?

Hi, here's what the functions.php file includes

Hmm, your HTML isn't matching what our function should be outputting.

Any other functions anywhere? In the Code Snippets plugin maybe?

No, I don't have Code Snippets installed. But I install a plugin called Schema. Does it affect things there?

No, it shouldn't. I just tried the code on my test site and it is indeed working.

Can you try adding the function using the Code Snippets plugin just to test?

I tried using the plugin, Still not work. Anyway, thank you very much for the effort :)

Hmm, something must be conflicting.

Any chance you can send me temporary admin login details so I can take a closer look?: https://generatepress.com/contact

If so, be sure to mention this topic.

Thanks!

This archived topic is closed to new replies.