Home › Forums › Pro Support › How to add the Updated Date on the Homepage with WP Show Posts PRO
- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by
elvin.
-
AuthorPosts
-
January 12, 2021 at 1:02 pm #25356
Charbel
ParticipantHello Team,
How can I add the updated date with or without the published date for the Posts on my homepage?
Here is my staging site: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/
I have a list called: Custom with pagination show posts for the 11 articles in my homepage.
I have also function in GeneratePress Child Theme (functions.php) to add the updated date on the Author page, as well as for a single post.
// Show the “Updated” Post Date in Header Element function post_modified_date() { return get_the_modified_date(); } add_shortcode( 'modified_date', 'post_modified_date' ); // Display the date a post was updated in the GeneratePress 3.0 theme // https://gist.github.com/brianleejackson/d98aad3831cbe934ddc21e50b08d4e39 add_filter( 'generate_post_date_output', function( $output, $time_string ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>'; if ( get_the_date() !== get_the_modified_date() ) { $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">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 );
I need also to add the Updated date for my homepage.
January 12, 2021 at 6:55 pm #25372elvin
ModeratorHi,
To clarify: Do you want to show the updated date only for the WPSP posts?
If so, this filter can help.
add_filter( 'wpsp_post_date_show_updated_only', '__return_true' );
I need also to add the Updated date for my homepage.
I’m not sure I understand what you mean by this. Can you explain a bit more? Thank you.
January 12, 2021 at 11:48 pm #25384Charbel
ParticipantHello @Elvin,
Thank you for your support.
What I want to accomplish is, to add the updated date and/or published date for the WPSP posts.
For example, if a post was published and was not updated at a later date, then I want to show the updated date.Please have a look at my author (blog) page, those are not WPSP posts: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/ You can see Published on or Updated on date.
I succeeded to add the published and updated date for a single article, as well as, for the author page articles by using the code mentioned above.I want to have the same for all WPSP posts which are showing on my homepage: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/
I hope this clear for you now.
January 13, 2021 at 12:34 am #25388Charbel
ParticipantHello @Elvin,
Here is additional details to have super clear picture:
I migrated from MH Magazine Theme to a GeneratePress Dispatch Theme, so I moved my date function.
The function below is for showing the published date, as well as the updated date across my entire site with the following format: Jan 4, 2021 | Updated on Jan 4, 2021– Author Page: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
– Homepage for WPSP Posts: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com
– Articles: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/export-all-nsg-rules-from-all-azure-subscriptions-with-powershell//***** Adding Last Modified Date Blog (Old Code) *****/ // A non-numeric value encountered post-meta.php on line 169 // function et_last_modified_date_blog( $the_date ) { if ( 'post' === get_post_type() ) { $the_time = get_post_time( 'His' ); $the_modified = get_post_modified_time( 'His' ); $published = sprintf( __( '%s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) ); $last_modified = sprintf( __( 'Updated on %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) ); $date = $the_modified !== $the_time ? $published . ' | ' . $last_modified : $published; return $date; } } add_action( 'get_the_date', 'et_last_modified_date_blog' ); add_action( 'get_the_time', 'et_last_modified_date_blog' );
The problem with that function, it’s throwing the error below on the author page (only):
http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
However, the published and updated date are still showing (e.g. Jan 4, 2021 | Updated on Jan 4, 2021) as you can see. The error is showing because I have enabled WP Debug set to True to debug another issue, then I found that the function above is causing it.
Warning: A non-numeric value encountered in /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/generatepress/inc/structure/post-meta.php on line 169
I have checked with GeneratePress premium support forum, and they said my current function: Right now it’s making it so the
get_the_time()
function isn’t returning a unix timestamp (which is a number). So the+
is adding a non-number (because of the filter) to a number.What do you recommend, and what is the best approach to use so we can show both the published + updated date for readers and Google across Author Blog Page, Article(s), and WPSP Posts?
Thank You!
-CharbelJanuary 14, 2021 at 12:59 am #25443Charbel
ParticipantHello @Elvin,
I have implemented the method noted by GeneratePress here: https://docs.generatepress.com/article/show-the-updated-post-date/ entirely including the Show the “Updated” Post Date in Header Element:
I was able to show the updated date for the Author blog Page here: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/author/charbel-nemnom/
For the single article(s), I added the Published on {{post_date}} | Updated on [modified_date] under Elements | Single Post:
Check it here: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com/export-all-nsg-rules-from-all-azure-subscriptions-with-powershell/However, the updated date is NOT showing on the Homepage for WPSP Posts, the published date is displayed only: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com
I am using WPSP Pro Edition. Could you please advise on how can I show the updated date for WPSP Posts as well?
Thank You @Elvin
January 14, 2021 at 2:07 am #25456elvin
ModeratorHowever, the updated date is NOT showing on the Homepage for WPSP Posts, the published date is displayed only: http://wpcharbelnemnomblog.northeurope.cloudapp.azure.com
Can you try adding this PHP snippet:
add_filter( 'wpsp_post_date_show_updated_only', '__return_true' );
And this CSS:
time.wp-show-posts-updated { display: block !important; }
Let us know how it goes.
-
AuthorPosts
- You must be logged in to reply to this topic.