- This topic has 9 replies, 3 voices, and was last updated 3 years, 4 months ago by
David.
-
AuthorPosts
-
September 12, 2019 at 12:34 am #1007370
Johanna
I want to display last modified dates and hide published date on my blog (without a plugin).
I tried Toms fixes:
https://generatepress.com/forums/topic/post-updated-date/#post-470725
https://generatepress.com/forums/topic/modified-post-date/#post-171970And this specific PHP Code doesn’t work:
add_action( 'generate_after_entry_header', 'tu_page_meta' ); function tu_page_meta() { if ( is_singular( 'page' ) ) : ?> <div class="entry-meta"> <?php generate_posted_on(); ?> </div><!-- .entry-meta --> <?php endif; }
September 12, 2019 at 5:49 am #1007579David
StaffCustomer SupportHi there,
the first of those Two Links you provided should still work.
Where did you add that code?
And do you have any other code that is effecting the way the date/time is being displayed?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 12, 2019 at 7:33 pm #1008296Johanna
Hey David,
So I’m using a combination of Functions.php and CSS.
Here are the codes:
Functions.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 ) ); }
CSS:
.posted-on .updated {
display: inline-block;
}
time.entry-date.published {
display: none;
}This worked to change the code on the page but doesn’t seem to work in SERPs.
For instance, I look at my results in SERP for the article: https://www.dherealmark.com/grammarly-plagiarism-checker/ for query “Grammarly vs Turnitin” (I’m around pos 6) and it displays the published date and not the modified date.
September 13, 2019 at 8:56 am #1008789David
StaffCustomer SupportCheck with your SEO setup or any other plugin you’re using for SEO Meta – currently you have published and update meta tags in the <head> of your site.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 15, 2019 at 8:50 pm #1010278Johanna
I currently use Yoast SEO do you think that could conflict?
And not sure about the meta tags but attached a screenshot of my tags: https://imgur.com/a/u71vv5K
September 16, 2019 at 9:54 am #1010852Tom
Lead DeveloperLead DeveloperTry this instead:
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">%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 );
No CSS needed 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 28, 2019 at 5:56 pm #1021524Johanna
I pasted your PHP code into my functions.php file and removed the CSS code but I don’t see any changes.
Tried it here: https://www.dherealmark.com/best-11-inch-laptop/
That article is on first page of Google but doesn’t seem to have modified date in both SERP or post page.
September 29, 2019 at 9:13 am #1021969Tom
Lead DeveloperLead DeveloperHmm, that code doesn’t seem to be taking effect. Do you have any other
generate_post_date_output
filters?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 29, 2019 at 9:41 pm #1022215Johanna
Not that I know of.
Here’s a screenshot of the placed snippet: https://imgur.com/a/fpiz4jC
And here’s an ss of my plugins: https://imgur.com/a/HhAw2sq
September 30, 2019 at 3:44 am #1022340David
StaffCustomer SupportHi there,
what is the code directly above it – ending line 199? There shouldn’t be open HTML in a functions.php file.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.