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. Before adding code like this you may want to instead create a Dynamic Template for your posts so you can design them exactly how you want via the WPBakery page builder.

// Adds new block to the Blog post blocks that shows up in the Customizer.
add_filter( 'wpex_blog_single_blocks', function( $blocks ) {
	$blocks['last_updated'] = __( 'Last Updated', 'total' );
	return $blocks;
} );

// Displays new block on the front-end.
add_filter( 'wpex_blog_single_layout_blocks', function( $blocks ) {
	if ( isset( $blocks['last_updated'] ) ) {
		$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;
} );

Result:

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)