[Resolved] Remove published date when using Page Header

Home Forums Support Remove published date when using Page Header

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #896863

    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">
    	<div class="entry-meta">
    		<span class="byline">

    Thank you very much

    Lead Developer
    Lead Developer

    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 πŸ™‚



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

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

    Lead Developer
    Lead Developer

    Ah, sorry – try adding this CSS as well:

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

    It works like a charm!
    Thank you so much

    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.