- This topic has 22 replies, 2 voices, and was last updated 4 years, 4 months ago by
David.
-
AuthorPosts
-
January 18, 2020 at 12:26 am #1135755
Suraj Katwal
I have an issue with the code too.
Let’s say
Case 1. When I have published the post today, it should show something like this
January 18, 2020 by Author Name
but it’s showing Last Updated on: January 18, 2020 by Author Name
Case 2. When I actually updated the post, it is working fine. showing
Last Updated on: January 18, 2020 by Author NameIs it possible to get like in case 1?
January 18, 2020 at 2:25 am #1135800David
StaffCustomer SupportHi there,
use the original code provided here:
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date
Then update this line for the update-date:
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%4$s</time>';
to:
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
January 18, 2020 at 3:31 am #1135836Suraj Katwal
It’s not working
add_filter( 'generate_post_date_output', function( $output, $time_string ) { $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="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %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() ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); }, 10, 2 );
January 18, 2020 at 3:31 am #1135837Suraj Katwal
It’s not working
add_filter( 'generate_post_date_output', function( $output, $time_string ) { $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="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %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() ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); }, 10, 2 );
Everything is fine but when I hit the publish button for the first time it’s showing Last Updated Date Text.
Thank YouJanuary 24, 2020 at 12:02 am #1142262Suraj Katwal
Any Update?
January 24, 2020 at 5:26 am #1142456David
StaffCustomer SupportHi there,
sorry we missed your replies – somehow they slipped through our system.
Try this code – it will compare date strings – so should only show updated if the there is a days difference:add_filter( 'generate_post_date_output', function( $output, $time_string ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>'; if ( get_the_date() !== get_the_modified_date() ) { $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %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() ) ); return sprintf( '<span class="posted-on">%s</span> ', $time_string ); }, 10, 2 );
October 10, 2020 at 4:37 am #1481738Franklin
where to find the file to make this change?
I can’t find it in functions.php
October 10, 2020 at 6:29 am #1481869David
StaffCustomer SupportHi there,
that code is PHP – this article explains:
https://docs.generatepress.com/article/adding-php/
However things have changed since this topic. I have replied directly to your topic to answer this.
-
AuthorPosts
- You must be logged in to reply to this topic.