about displaying the Last Updated date

Hello Aigars

I am using the Travelify theme for my website sandeepachetan.com.

I was looking to change the Published date to the Last Modified date in all my posts. Only one date will be displayed. In the posts that have been updated, it will be the modified post date. In the ones without any change, the original, published date will be displayed.

I did the following changes in the file /themes/travelify/library/functions/functions.php

if ( ! function_exists( 'travelify_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function travelify_posted_on() {
	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
		$time_string = '<time class="entry-date updated" datetime="%3$s">%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() )
	);
	$byline = sprintf(
		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
	);
	echo  '<span class="byline"> ' . $byline . '</span><span class="posted-on">' . '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . "Last Updated: ". $time_string . '</a>' . '</span>';
}
endif;

It does what I need. But I am not sure with this change, whether the search engine would see this as an updated post or a new post with duplicate content.

Could you please have a look at the code above and let me know if I need to do this any other way?

Thank you so much!

Hi @sandeepachetan,

I hope you are well today and thank you for your question.

You can achieve this by changing that code as following.

 /**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function travelify_posted_on() {
	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
	$time_string = sprintf( $time_string,
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date() )
	);
	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
		$time_string = sprintf( $time_string,
		esc_attr( get_the_modified_date( 'c' ) ),
		esc_html( get_the_modified_date() )
	);
	}

	$byline = sprintf(
		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
	);
	echo '<span class="byline"> ' . $byline . '</span><span class="posted-on">' . '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark"> Last Updated: ' . $time_string . '</a>' . '</span>';
}

Please note you are making changes in the theme files therefore you have to make these changes again after theme updation as changes made in the theme files get lost on theme updation.

To avoid this please try using the attached child theme of travelify theme that contains the above code.

Best Regards,
Movin