How to Display the Last Updated Date of Your Posts in WordPress

,


Show Last Updated Date Before Post Content ( using functions.php )

Add the following code in your functions.php file

function last_updated_date( $content ) {
 $u_time = get_the_time('U'); 
 $u_modified_time = get_the_modified_time('U'); 
 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'); 
  $custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
 }  
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'last_updated_date' );

Add Last Updated Date in Theme Templates

Add the following code in your required theme file ( Example: single.php )

$m_time = get_the_time('U'); 
$modified_time = get_the_modified_time('U'); 
if ($modified_time >= $m_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; } 





Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.