[Resolved] Regarding “Updated Date”

Home Forums Support Regarding “Updated Date”

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1405729
    Mini

    Hello,

    I used this code to show updated post in the article page. But I would like to show updated post date in the SERP as well.Can you help me with the same.

    .posted-on .updated {
    display: inline-block;
    }

    .posted-on .updated + .entry-date {
    display: none;
    }
    .posted-on .updated:before {
    content: “Last Updated “;
    }

    Thanks in advanced.

    #1405970
    David
    Staff
    Customer Support

    Hi there,

    Remove that CSS – and add this PHP snippet to your site:

    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>';
    
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
    
        if ( $updated_time > $published_time ) {
            $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="date-label>Last Updated </span><span class="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );

    Reference:

    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    This will display ONLY the Updated date on the post if one is available. Otherwise it will show the Published date – both will be prefixed with: Last Updated.

    How Google interprets your date is upto it.

    #1406199
    Mini

    Hello David,

    I removed CSS and this PHP Snippet to my site.

    Moreover,I want to show “Last Updated on” Text before the date in the article page.

    How can I do that?

    #1406597
    Mini

    One more issue I found that, now some post is shown last updated date at 2 places. One is below the blog title and one is below the feature image.

    Here is a blog link:- https://mywplife.com/email-marketing/rss-to-email/

    So you can check on your end as well.

    #1406828
    Tom
    Lead Developer
    Lead Developer

    To add the Last Updated on text, try this CSS:

    .updated-date:before {
        content: "Last updated on";
    }

    The second date seems to be inside your content itself – can you see it/a shortcode within the post content when editing the post?

    #1407193
    Mini

    Thanks Tom.

    I removed that shortcode, now everything is workinhg fine.

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