- This topic has 9 replies, 4 voices, and was last updated 6 years ago by Leo.
-
AuthorPosts
-
January 13, 2018 at 11:56 pm #470419Chandan
Hello,
I need to show last updated date instead of published date. I did the following but there is some problem.
.posted-on .updated { display: inline-block; } .posted-on .updated:before { content: "Last updated: "; } time.entry-date.published { display: none; }
Above shows updated for the post which was updated but blank which was not updated since published.
So I am looking for fixes which do the following.
Show Last updated when post was modified
Show original published date if post is not updatedThis should also reflect in the source code. Currently, it shows published_time and modified_time both.
January 14, 2018 at 9:41 am #470725TomLead DeveloperLead DeveloperIf you want to only show the modified date in the source if it’s set, you can scrap that CSS and use this PHP:
add_filter( 'generate_post_date_output', 'tu_show_modified_date' ); function tu_show_modified_date() { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>'; } $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ) ); printf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ) ); }
Let me know 🙂
January 15, 2018 at 3:31 pm #471810ChandanHello Tom,
It’s not working as expected.
I removed those CSS and added what you mentioned in functions.php file of the child theme.
I still don’t see last updated time on the blog post. Ex – https://geekflare.com/google-cloud-latency/ this still shows June but post was updated in November.
Source code still has both times.
<meta property=”article:published_time” content=”2017-06-15T22:04:32+08:00″ />
<meta property=”article:modified_time” content=”2017-11-12T14:40:47+08:00″ />Please help. As mentioned earlier, I want to show only last updated time on a blog post and source code. However, if post is not updated then show the original published time.
January 15, 2018 at 8:11 pm #471896TomLead DeveloperLead DeveloperI just adjusted the code a bit to test if it’s working at all – can you update it and let me know?
January 16, 2018 at 1:25 am #471972ChandanIt has no affect at all. Still, the same as you can see here – https://geekflare.com/google-cloud-latency/
January 16, 2018 at 9:32 am #472414TomLead DeveloperLead DeveloperI think I see the issue – I just adjusted the code above.
March 15, 2018 at 8:25 am #520753ToddI have been trying to get this updated dates to work on test site.
I have 2 snippets in place and the CSS you recommended from another post and the meta remains on 2 lines.
http://nxts847332.nextsearch.io/blog/
CSS – https://generatepress.com/forums/topic/all-meta-in-one-single-line/#post-108079
March 15, 2018 at 5:20 pm #521108LeoStaffCustomer SupportHi there,
Instead of:
.posted-on .updated { display: block; }
Try this:
.posted-on .updated { display: inline-block; }
If this doesn’t help can you open a new topic?
Thanks!
March 15, 2018 at 9:09 pm #521218ToddThat worked, Thank you!
I did notice that the date that shows in WP Show posts and the rest of the site seems different. I will send an email into the support on that plugin since I have a pro version of that also.
March 15, 2018 at 9:34 pm #521229LeoStaffCustomer SupportNo problem!
-
AuthorPosts
- You must be logged in to reply to this topic.