News:

Please post your question in the right forum. We will answer it as soon as possible.

Main Menu

How to show last updated date of post instead published date in WordPress?

Started by DJ RONY, January 11, 2021, 12:42:22 PM

Previous topic - Next topic

DJ RONY

In your theme/child theme's functions.php file add the following code.


/*showing last updated of post instead published date*/
function wpb_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', 'wpb_last_updated_date' );

I do what I love, Money Comes on the Way.