- This topic has 17 replies, 3 voices, and was last updated 4 years, 10 months ago by Tom.
-
AuthorPosts
-
January 28, 2020 at 3:55 pm #1147618Scott
Hi there
I’ve followed the instructions in the discussion below, and now have Last Updated dates displaying in my Page Hero under my H1.
My first question relates to the dates themselves. They are all displaying dates from the past 2 days, even if no change has been made to these posts. What triggers the [modified_date] to be updated?
Second question:
I’m using the below CSS to change the font size.
.hero-meta {
font-size: 18px;
}It is working well for desktop but is too large on mobile. I’ve tried adding the below with no success:
@media (max-width: 768px)January 29, 2020 at 2:37 am #1147942DavidStaffCustomer SupportHi there,
was it just this code you used:
https://generatepress.com/forums/topic/how-to-show-the-last-updated-post-date-when-using-page-header-edit-element/#post-1147383Let me know
January 30, 2020 at 1:28 pm #1149788ScottHi David
Yes. Here’s what I’ve done:
Add the below PHP:
function display_modified_date_shortcode () {
$mod_date = get_the_modified_date();
if ( get_the_date() !== $mod_date ) {
return ‘Last Updated: ‘ . $mod_date;
}
}
add_shortcode( ‘modified_date’, ‘display_modified_date_shortcode’ );Added the below under the H1 in my Page Hero Header element:
[modified_date]
Added the below CSS to edit the text size:
.hero-meta {
font-size: 18px;
}January 30, 2020 at 5:59 pm #1149891TomLead DeveloperLead DeveloperInstead of introducing new code, I would just use the standard
{{post_date}}
Then you can tell that template tag to show the updated date with a filter:
add_filter( 'generate_page_hero_post_date', function() { $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 = 'Last Updated: <time class="entry-date-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() ) ); return $time_string; } );
Let me know 🙂
January 31, 2020 at 12:45 am #1150022ScottHi Tom
Thanks for your reply.
So, I’ve replaced the previous PHP with the code in your message above.
I’ve then replaced [modified_date] under my H1 with {{post_date}}.
The result is it now displays “Last Updated:” but with no date.
Any ideas?
January 31, 2020 at 10:54 am #1150721TomLead DeveloperLead DeveloperHmm, that means the WP core function
get_the_modified_date()
isn’t doing anything on your site.Do you have any other custom functions added?
January 31, 2020 at 12:41 pm #1150805ScottNope, this is it as far as I’m aware.
January 31, 2020 at 5:16 pm #1150933TomLead DeveloperLead DeveloperAre your date and time format configured in “Settings > General”?
January 31, 2020 at 5:24 pm #1150938ScottYep. And they were appearing OK when applying the earlier code from David, it’s just the dates didn’t seem correct.
January 31, 2020 at 5:26 pm #1150941TomLead DeveloperLead DeveloperCan you try the updated code?: https://generatepress.com/forums/topic/last-updated-date-displaying-as-yesterdays-date-for-all-posts/#post-1149891
January 31, 2020 at 5:45 pm #1150953ScottOK, so using the updated code, the date is now displaying under the H1. However, it seems to have the same issue as earlier, where all dates are very recent (last few days), even if the post hasn’t been modified. Would something like the sidebar changing due to a related post widget trigger the modified date? Or does the content of the post itself need to change?
Also, I’ve enabled post date in archive in Layout > Blog and interestingly this displays the original post date, not the modified date.
February 1, 2020 at 9:37 am #1151444TomLead DeveloperLead DeveloperAre you sure the posts haven’t been modified? What’s the latest modified date for them in the Dashboard?
These are all core WordPress functions, so if they’re malfunctioning it means something on your installation/server is configured wrong.
February 1, 2020 at 12:54 pm #1151620ScottI can’t find the modified date in the dashboard, only published.
Regardless, I think they all must have been “modified” by some work I was doing a few days ago with the categories.
Same issue discussed here: https://wordpress.stackexchange.com/questions/135268/how-to-update-the-modified-time-of-a-post-only-when-content-is-changed
I’m OK to leave it for now.
Any tips for changing text size on mobile per my original post?
February 1, 2020 at 4:43 pm #1151729TomLead DeveloperLead DeveloperGive this a shot:
@media (max-width: 768px) { .hero-meta { font-size: 18px; } }
February 1, 2020 at 7:07 pm #1151781ScottHmm yeah that’s what I had tried already. Just tried again with no success.
So I have this in my Page hero element:
<br>
<br>
<h1>{{post_title}}</h1>
{{post_date}}And this in my Additional CSS:
@media (max-width: 768px) {
.hero-meta {
font-size: 8px;
}
}Does that look right?
-
AuthorPosts
- You must be logged in to reply to this topic.