How to Display 「Last Updated」 instead of 「Published」 Date

How to Display 「Last Updated」 instead of 「Published」 Date

Astra by default displays the date when a post was published to your website visitors. Plus it adds the date when the post was last updated in the code – for SEO and Schema Markup.

Published date is displayed in the front end

Both, published as well as updated dates are available in the markup.

If you want to display last updated date for the post to your visitors, use the following custom code –

/**
* Display only last modified date in the post metadata.
*
* @param String $output Markup for the last modified date.
* @return void
*/
function your_prefix_post_date( $output ) {
$output = '';
$format = apply_filters( 'astra_post_date_format', '' );
$modified_date = esc_html( get_the_modified_date( $format ) );
$modified_on = sprintf(
esc_html( '%s' ),
$modified_date
);
$output .= '';
$output .= ' ' . $modified_on . '';
$output .= '';
return $output;
}
add_filter( 'astra_post_date', 'your_prefix_post_date' );

It hides the published date and makes updated date visible.

Note:

Add the above code into the child theme』s functions.php file.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注