Site logo

Archived topic

Remove published date when using Page Header

5 replies · Started by Huy on May 12, 2019

Viewing posts 1–6 of 6

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

Hi 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 :)

Tom

I used the code and the published date is completely removed from HTML

However, the Updated date still hasn't shown up.

Ah, sorry - try adding this CSS as well:

.page-hero time.updated {
    display: inline-block;
}

Leo
It works like a charm!
Thank you so much

You're welcome :)

This archived topic is closed to new replies.