- This topic has 5 replies, 2 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
May 12, 2019 at 5:35 am #896863
Huy
Hi there
It seems like my question was asked many times before. However, I think my question is a little bit specific
As the topic, I want to remove the published date (from HTML code) of a post when using a Page Header
– I read this topic: https://generatepress.com/forums/topic/last-updated-date-does-not-show-in-google/#post-792504. Then followed it, it works well with normal post. However, it still showed the published date in the code when I put them in the Page header (I used {{post_date}})
– Then I read this guide: https://docs.generatepress.com/article/generate_post_date_output/. However, when I created a shortcode and insert it in my page header. It showed, however, just plain text. I want it to be covered in a proper tag like this: http://prntscr.com/nnjdzx. Not just a text. So I used {{post_date}} and hope that the PHP code can remove the published date from that
Please show me how to solve this. And it would be good if you have a code that both removes published date in both normal posts and posts with Page Header
This is the code I used for header
<header class="entry-header"> <h1 class="entry-title" itemprop="headline"> {{post_title}} </h1> <div class="entry-meta"> {{post_date}} <span class="byline"> {{post_author}} </span> </div> </header>
Thank you very much
May 12, 2019 at 8:29 am #897048Tom
Lead DeveloperLead DeveloperHi there,
I assume you’re using a Header Element?
If so, try this function:
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 = '<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() ) ); return $time_string; } );
Let me know ๐
May 12, 2019 at 8:59 am #897083Huy
Tom
I used the code and the published date is completely removed from HTML
However, the Updated date still hasn’t shown up.
May 12, 2019 at 9:01 am #897087Tom
Lead DeveloperLead DeveloperAh, sorry – try adding this CSS as well:
.page-hero time.updated { display: inline-block; }
May 12, 2019 at 9:04 am #897090Huy
Leo
It works like a charm!
Thank you so muchMay 12, 2019 at 3:03 pm #897286Tom
Lead DeveloperLead DeveloperYou’re welcome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.