Site logo

Archived topic

Add last updated date to posts

11 replies · Started by Robert on February 20, 2022

Viewing posts 1–12 of 12

Hi there,
I'm trying to add last updated date to posts but no luck.
Found this css code when I searched topics but didn't work?

;

body:not(.blog,.archive) .posted-on .updated:before {
content: " | Last Updated ";
}

body.blog .posted-on .updated:before,
body.archive .posted-on .updated:before {
content: "Last Updated ";
}

any suggestions?

I tried adding this to functions.php but didn't work;

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' );

Thanks for the reply.
I'd prefer just the updated date if it's not a hassle?

I noticed there's a plugin for php but is that wise to use?

Hi Robert,

The CSS should work, can you link us to your post which has been updated?

That worked!
So, just to confirm using the functions.php file isn't recommended? Doesn't work?
Does css degrade site speed over time if too much is used?
Thanks

So, just to confirm using the functions.php file isn’t recommended? Doesn’t work?

It's not needed. As the updated date and post date are both already in the HTML.

Does css degrade site speed over time if too much is used?

Yes, if we are talking about hundreds and thousands lines of CSS.

You are welcome :)

thanks again for the help

No problem :)

This archived topic is closed to new replies.