Home / Admin / How To Show Last Modified Date On Blog Post Instead Of Published Date in WordPress
Duplicate Snippet

Embed Snippet on Your Site

How To Show Last Modified Date On Blog Post Instead Of Published Date in WordPress

If you want to display the last modified date on your blog post without using a plugin in WordPress, you can achieve this by modifying your theme files. Here's how to do it without a plugin:

Code Preview
php
<?php
// Post Date Function
function post_date(){
	// If modified date
	if ( get_the_date() !== get_the_modified_date() ) {
		$dateTime = get_the_modified_date( 'c' );
		$itemropType = 'dateModified';
		$date = '<span>'. get_the_modified_date() .'</span>';
		
	} else { // If published date
		$dateTime = get_the_date( 'c' );
		$itemropType = 'datePublished';
		$date = '<span>'. get_the_date() .'</span>';
	}
	return '<time class="date" datetime="'.$dateTime.'" itemprop="'.$itemropType.'">'.$date.'</time>';
}
// Display - echo function 
echo post_date();

Comments

Add a Comment