- This topic has 13 replies, 3 voices, and was last updated 1 year ago by
David.
-
AuthorPosts
-
March 24, 2020 at 7:54 am #1208604
Nacho
Hello Tom,
How do you hide the updated date when the has just been published and there is no update?
I have this CSS code:
.posted-on .updated { display: inline-block; } .posted-on .published:before { content: "Publicado el "; } .posted-on .updated:before { content: "Actualizado el "; } .posted-on { display: inline-flex; } .entry-date { order: -1; margin-right: 10px; border-right: 1px solid #ddd; padding-right: 10px; }
I want to show the updated date when it´s been updated but no when it´s just been published.
Thanks a lot.
March 24, 2020 at 9:32 am #1208680Leo
StaffCustomer SupportHi there,
I believe this is what you are looking for:
https://generatepress.com/forums/topic/hide-modified-date-if-is-the-same-as-posted-date/#post-1199125Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know if this helps 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 24, 2020 at 12:39 pm #1208866Nacho
Hello Leo,
I´ve just inserted that code but know the published date is shown twice.
Is this fixable?
Thanks a lot.
March 24, 2020 at 1:17 pm #1208900Leo
StaffCustomer SupportCan you remove your own CSS first?
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 24, 2020 at 1:33 pm #1208917Nacho
Hi Leo,
Sure, I´ve just did it.
Also, I´ve changed the URL to other one so we can run the tests in the website that is for testing purposes.
Let me know.
Thanks a lot.
March 24, 2020 at 1:38 pm #1208921Nacho
Hi Leo,
I did not say it but if we need to show both the published date and the updated date when those are in different dates but if there is no updated date, just show the published date.
Thanks a lot.
March 24, 2020 at 1:39 pm #1208922Leo
StaffCustomer SupportJust to confirm, this PHP snippet is all you are using right now?
https://generatepress.com/forums/topic/hide-modified-date-if-is-the-same-as-posted-date/#post-1199125I just tested it and it seems to work by default without any CSS added.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 24, 2020 at 1:45 pm #1208924Nacho
Hi Leo,
Yes, that one and without the CSS.
As you can see in the image, it´s showing the published date twice: https://d.pr/i/EmHyFp
Thanks.
March 24, 2020 at 5:15 pm #1209032Leo
StaffCustomer SupportDo you happen to have any other filters or functions added related to meta?
The code is working for me like this:
https://wordpress-202309-991531.cloudwaysapps.com/2020/03/23/test-post/
https://wordpress-202309-991531.cloudwaysapps.com/2020/03/25/test-3/Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 25, 2020 at 12:08 am #1209172Nacho
Hello Leo,
I have this one below that deactivates the links in the dates:
add_filter( 'generate_post_date_output','tu_remove_date_link', 10, 2 ); function tu_remove_date_link( $output, $time_string ) { printf( '<span class="posted-on">%s</span>', $time_string ); }
Deactivating that filter it seems to be working but I want to get rid off the link for the date. How can I have both?
Hope it helps.
Thanks a lot.
March 25, 2020 at 12:27 am #1209180Nacho
Hello Leo,
It seems to be working fine with just that filter. Now the problem is that it looks weird on mobile.
With just the CSS you´ve provided it looks super fine, dates in two columns but with the filter it does not even with both filter and the CSS.
The code with the filter + CSS is like this:
Filter:
add_filter( 'generate_post_date_output', function( $output, $time_string ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Publicado el: %2$s</time>'; if ( get_the_date() !== get_the_modified_date() ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Publicado el: %2$s</time><time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Actualizado el: %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 );
CSS:
.entry-date.published { order: -1; margin-right: 10px; border-right: 1px solid #ddd; padding-right: 10px; }
Here is the screenshot with the CSS: https://d.pr/i/9XH6F0 and here with the filter + CSS: https://d.pr/i/RdgidR
Is there a way to have the filter one looking like if I was using the CSS?
Thanks a lot.
March 25, 2020 at 6:46 am #1209469David
StaffCustomer SupportHi there,
try adding this CSS:
.posted-on { display: flex; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 25, 2020 at 7:32 am #1209535Nacho
Hello David,
That worked like charm.
Thanks a lot for your help!
Have a nice day.
March 25, 2020 at 9:06 am #1209784David
StaffCustomer SupportGlad we could be of help
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.