Snippets: Add A Last Updated On Section to Blog Posts

Once you add this code you can go to Appearance > Customize > Blog > Single and you will find the new block in the layout blocks at the bottom of the tab so you can move it around to where you want it.

add_filter( 'wpex_blog_single_layout_blocks', function( $blocks ) {

	$blocks['last_updated'] = function() {

		$original_time = get_the_time( 'U' ); 
		$modified_time = get_the_modified_time( 'U' );

		if ( $modified_time >= $original_time + 86400 ) {

			$updated_time = get_the_modified_time( 'h:i a' );
			$updated_day = get_the_modified_time( 'F jS, Y' );

			echo '<div class="last-modified">This post was last updated on ' . $updated_day . ' at ' . $updated_time . '</div>';

		}

	};

	return $blocks;

} );

add_filter( 'wpex_blog_single_blocks', function( $blocks ) {
	$blocks['last_updated'] = __( 'Last Updated', 'total' );
	return $blocks;
} );

Result:

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.