Site logo

Archived topic

Last modified date in Google results

5 replies · Started by Bijaya on March 16, 2021

Viewing posts 1–6 of 6

Hi there,

I have been using the following code snippet since 2 years or so to mainly "enable my site to show last updated info on site and on Google".

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() ),
			get_avatar( get_the_author_meta( 'ID' ) )
		)
	);

	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}

	$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="updated" 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
	);
}

As I am migrating to a new site (probably marketer starter site), I want to make sure that the above code is relevant and necessary.

1) Above code is 2 years old or more... so I want to confirm if this issue is patched in the newer themes? If not (which is absolutely okay), do I need to add the above code as it is?

2) While I was creating this ticket, I saw a lot of other threads and tickets about the same issue. Almost all had a different answer, a different solution and a different code snippet. One of most recent one was:
https://docs.generatepress.com/article/generate_post_date_show_updated_only/

I am confused... what is the correct option?

Thanks so much,
-Swadhin

Hi there,

1. that method is still relevant today - there are numerous post meta layouts we have provided as each user requirement and setup is different.

2. We introduced that filter to minimize the need for custom functions when only a post date change was required. But when it comes to a custom post meta element you're method is still applicable.

Good news - with GPP 2.0 you will be able to build Post Meta in the Block Element - so no need to custom code anymore :)

Thanks so much David. It clears every confusion I had.

Yes... I am so excited about GPP 2.0 I saw a video of it on the site and it is unlike anything we have seen. Dynamic content and lots more.. So excited!!

Me too! Glad to be of help

Hijacking this thread quick to ask an unrelated question: do you have an ETA for the release date for GPP 2.0 yet? :-)

Hi there, looking at another 2-3 weeks of alpha/beta testing before we reach a release candidate.

This archived topic is closed to new replies.