- This topic has 21 replies, 3 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
March 2, 2019 at 5:47 am #826396
epickenyan
Hi Tom. Did you ever get a solution to this?
March 2, 2019 at 6:24 am #826422David
StaffCustomer SupportHi there,
there is this solution where the user wanted the featured image appearing after the 2nd paragraph, the same principles apply with any content you wish to add:
https://generatepress.com/forums/topic/featured-image-inside-the-article/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 2, 2019 at 11:08 pm #827039epickenyan
Thanks, David, Will try it out. Btw, would you kindly help in solving this https://generatepress.com/forums/topic/how-to-show-updated-posts-with-plugin/#post-826692? Tom might have overlooked it. Google is also not picking my site’s updated date.
March 3, 2019 at 5:10 am #827207David
StaffCustomer SupportYou’re welcome. Looks like Tom has provided a resolution for that topic.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 3, 2019 at 7:40 am #827432epickenyan
The code shared also includes an author gravatar code. I just need the specific code to stop showing double last updated dates.Brian’s code in another support question worked. Will wait to see if Google will pick up the last updated date then revert.
March 3, 2019 at 9:25 am #827528Tom
Lead DeveloperLead DeveloperThis code is worth trying:
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> ', // WPCS: XSS ok, sanitization ok. $time_string ); }, 10, 2 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 3, 2019 at 9:28 am #827535epickenyan
Hi Tom. As already pointed out, that code (I tried the others too) shows double dates as shown in the screenshot I attached in the other post. Only Brian’s code (woorkup) seems to display properly.
March 3, 2019 at 4:28 pm #827829Tom
Lead DeveloperLead DeveloperThat code only prints one date. If you tried it and had multiple dates, you likely have another filter conflicting with it.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 3, 2019 at 10:13 pm #827943epickenyan
I don’t actually. I just had the CSS code that you recommend for showing updated date. Then adding the PHP code makes the date appear twice.
March 4, 2019 at 9:35 am #828573Tom
Lead DeveloperLead DeveloperHmm, that’s strange. If you’d like to link me to the page I can take a closer look. Otherwise, the code Brian shared works as well, it’s just not as future-proof.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 4, 2019 at 1:28 pm #828787epickenyan
Since it is a function, I don’t know how to target only a certain demo page so I can share here.
March 4, 2019 at 5:06 pm #828898Tom
Lead DeveloperLead DeveloperI just gave the function a shot on my localhost: http://prntscr.com/mtav81
Only 1
<time>
element is output in the source.Did you remove Brian’s code once you added the new function?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 4, 2019 at 10:20 pm #829055epickenyan
Hi Tom, removing these two lines of code stopped showing double updated dates.
esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ),
I also used this css
.posted-on .updated{display: inline-block;} .posted-on .updated + .entry-date{display:none;} .posted-on .updated:before{ content:"Updated On: ";}
Will removing that function affect my site negatively? Here is the source code after removing the function.
<span class="posted-on"><a href="https://www.example.com/url/" title="12:43 pm" rel="bookmark"><time class="updated" datetime="2019-02-27T12:43:59+03:00" itemprop="dateModified">Feb 27, 2019</time><time class="entry-date published" datetime="2019-02-27T12:43:23+03:00" itemprop="datePublished">Feb 27, 2019</time></a></span><span class="cat-links"><a href="https://www.example.com/category/example/" rel="category tag">Example</a></span><span class="posted-on"></span>
As I said earlier, I tested the code two weeks ago before I even discovered Brians code yesterday and it was still showing double dates. I reinstalled the theme and it still showed double dates until I removed the code above.
March 5, 2019 at 9:42 am #829716Tom
Lead DeveloperLead DeveloperYou shouldn’t need to make either of those adjustments. The code should work as is. I did make some changes yesterday, so make sure you re-add it from here: https://generatepress.com/forums/topic/hook-inside-content/#post-827528
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 5, 2019 at 1:24 pm #829891epickenyan
I used your updated code. Still showed two updated dates. I removed the CSS code except this one
.posted-on .updated + .entry-date{display:none;}
and one date disappeared, but now I cannot add a prefix to the new date. Here is the source code after doing that:<span class="posted-on"><a href="https://www.example.com/url/" title="12:55 pm" rel="bookmark"><time class="updated" datetime="2019-02-22T20:23:56+03:00" itemprop="dateModified">Feb 22, 2019</time><time class="entry-date published" datetime="2018-12-20T12:55:01+03:00" itemprop="datePublished">Dec 20, 2018</time></a></span><span class="cat-links"><a href="https://www.example.com/category/example/" rel="category tag">Example</a></span><span class="posted-on"><time class="entry-date updated-date" datetime="2019-02-22T20:23:56+03:00" itemprop="dateModified">Feb 22, 2019</time></span>
I was able to show the updated date on Google using Brian’s code (checked recently crawled URLs). But I cannot get this one of yours to stop showing dates twice.
—————————————————————————————-
I did get the prefix to work with this css code though..posted-on .updated + .entry-date{display:none;} .entry-date.updated-date:before{content:"Updated On: ";}
And this shows up in structured data testing tool http://prntscr.com/mtraf2 and http://prntscr.com/mtrcia
-
AuthorPosts
- You must be logged in to reply to this topic.