Published & Modified Date Shortcode

For more information, see Display last updated date on articles

/**
 * Published & Modified Date Shortcode 
 *
 * @link https://www.billerickson.net/code/published-modified-date-shortcode
 *
 */
function be_published_modified_date_shortcode() {
	$date = get_the_date( 'U' );
	$updated = get_the_modified_date( 'U' );

	$output = '<span class="entry-date"><span class="label">Published on</span> ' . get_the_date( 'F j, Y' ) . '</span>';
	if( $updated > ( $date + WEEK_IN_SECONDS ) )
		$output .= ' <span class="entry-date-modified"><span class="label">Updated on</span> ' . get_the_modified_date( 'F j, Y' ) . '</span>';

	return $output;
}
add_shortcode( 'be_published_modified_date', 'be_published_modified_date_shortcode' );
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk