Skip to content

Instantly share code, notes, and snippets.

@AndreFCAmorim
Created November 6, 2022 15:45
Show Gist options
  • Save AndreFCAmorim/5a56e20cd89cdde6816aea4ca0508f40 to your computer and use it in GitHub Desktop.
Save AndreFCAmorim/5a56e20cd89cdde6816aea4ca0508f40 to your computer and use it in GitHub Desktop.
Display the Last Updated Date on WordPress
<?php
$u_time = get_the_time( 'U' );
$u_modified_time = get_the_modified_time( 'U' );
// Only display modified date if 24hrs have passed since the post was published.
if ( $u_modified_time >= $u_time + 86400 ) {
$updated_date = get_the_modified_time( 'F jS, Y' );
$updated_time = get_the_modified_time( 'h:i a' );
$updated = '<p class="last-updated">';
$updated .= sprintf(
// Translators: Placeholders get replaced with the date and time when the post was modified.
esc_html__( 'Last updated on %1$s at %2$s' ),
$updated_date,
$updated_time
);
$updated .= '</p>';
echo wp_kses_post( $updated );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment