[Resolved] Correct way to show only Modified Date on page hero

Home Forums Support Correct way to show only Modified Date on page hero

  • This topic has 6 replies, 3 voices, and was last updated 3 months ago by Tom.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1343849
    Emmanuel

    Hi Tom,

    I have read through the forum and managed to display Updated Date on Page Hero using this shortcode:

    I have also read this post: https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date and added the code in my functions.

    Then I read here that one should only display the modified date in order for Google to display it in results. My test in structured data shows both updated and published date.

    How can I completely disable published date so that Google could pick it up? He did not mention how he solved it.

    Thanks

    #1344061
    Leo
    Staff
    Customer Support

    Hi there,

    Is this issue still happening?

    I’m only seeing updated date now.

    #1344170
    Emmanuel

    Hi Leo,
    Yes, it is still happening.

    On Google, it is showing the published dates for articles rather than the updated date.

    When I use this code provided by Tom the date is not displayed.

    #1344194
    Emmanuel

    Hello,

    So I added this code that Tom Provided:

    function display_modified_date_shortcode () {
        $mod_date = get_the_modified_date();
        if ( get_the_date() !== $mod_date ) {
            return sprintf(
                'Updated On <time class="updated" datetime="%1$s" itemprop="dateModified">%2$s</time>',
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( $mod_date )
            );
        }
    }
    add_shortcode( 'modified_date', 'display_modified_date_shortcode' );

    But the date does not display because of this CSS

    .page-hero time.updated {
        display: none;
    }

    Another thing I noticed is that if a post has not been updated the Updated Date will not show completely.

    #1344687
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You’re better off using the {{post_date}} template tag and doing this:

    add_filter( 'generate_page_hero_post_date', function() {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 1800;
    
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date-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;
    } );
    #1344765
    Emmanuel

    Hi Tom,

    Thanks. This works as expected.

    Regards

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