- This topic has 7 replies, 2 voices, and was last updated 4 years, 3 months ago by David.
-
AuthorPosts
-
November 25, 2017 at 2:47 pm #434161dale
Hi there.
On posts that I have updated after initially posting them, I want to display a “last updated” date in addition to the posting date. Initially I added this PHP via Code Snippets plugin, but it added the “last updated” text to pages as well as posts:
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' );
Wp Beginner, at http://www.wpbeginner.com/wp-tutorials/display-the-last-updated-date-of-your-posts-in-wordpress/, suggests adding something like this to the theme, but obviouly it would need to be in a child theme and I’m not sure where to put it (or if it’s correctly formatted for GP):
$u_time = get_the_time('U'); $u_modified_time = get_the_modified_time('U'); if ($u_modified_time >= $u_time + 86400) { echo "<p>Last modified on "; the_modified_time('F jS, Y'); echo " at "; the_modified_time(); echo "</p> "; }
Thoughts? Thanks!
November 25, 2017 at 9:17 pm #434328TomLead DeveloperLead DeveloperHi there,
Try adding this CSS:
.posted-on .updated { display: inline-block; } .posted-on .updated:before { content: "Last updated: "; }
November 26, 2017 at 6:24 am #434573dalesorry, I’m not following. do you mean to use the CSS without any PHP, or to use it with one of the coding options I mentioned above?
November 26, 2017 at 6:36 am #434596LeoStaffCustomer SupportJust that CSS above should do.
Have you given it a shot and not working?
November 26, 2017 at 9:28 am #434790daleYes, I gave it a shot and didn’t see any change. But I had Cloudflare on, so that might have been the issue. I just tried again (with CloudFlare in developer mode) and it worked!
Thanks! An easier solution than I expected ๐
November 26, 2017 at 6:10 pm #435124TomLead DeveloperLead DeveloperGlad I could help! ๐
June 22, 2020 at 5:46 pm #1338086EmmaHi there, I’ve tried adding this CSS and whilst it works, it’s pushed hard up against the published date so it looks bad. Is there any way to just show the last updated date? When I try to remove the published date (display post date) it removes the Last Updated date too.
ThanksJune 23, 2020 at 7:25 am #1338748DavidStaffCustomer SupportHi there,
if you want to just display the Latest date then you would better off using the PHP Snippet here:
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date
If you need any more help with it, raise a new topic where you can share a link to your site and we can assist.
-
AuthorPosts
- You must be logged in to reply to this topic.