• Hello David,
    hope you are fine.

    I want to show the Last Updated Date in GeneratePress for my blog readers and also for Google.
    Because showing the last updated date in Google is a good SEO practice.
    But according to GeneratePress, Show the “Updated” Post Date – Documentation. I’m a little confused.

    You can see the CSS code below.

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

    Someone told me that if I use the above CSS code. It only shows the last updated date to only blog readers but if I use the below custom function. it shows the last updated date to blog readers and Google too.

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %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="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );

    So David, please see the image below, I want to show the last updated date like the below image. So can you please suggest me which method I can use to show the last update date in GeneratePress?

    Last Updated.png

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Leo

    (@leohsiang)

    Hi there,

    That function should work. It’s the one here:
    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    Looks like you’ve added it and it’s working?

    I’m seeing the updated date in the HTML markup.

    Thread Starter Shivam Pandey

    (@wikihelp360)

    Leo, Can you share the screenshot where you see the updated date in the HTML markup and According to you, you suggest using the custom function to show the last updated date to blog readers or Google too and it is true that if I show the last updated date with CSS. it only shows the last updated date to the readers.

    Leo

    (@leohsiang)

    Thread Starter Shivam Pandey

    (@wikihelp360)

    Leo, I have used CSS code to show the last updated date in GeneratePress. But I have also checked that the last updated date is showing in the HTML markup. But according to you, you suggest to use the custom function to show the last updated date to readers or Google but the custom function you have shared is not working for me so below I have mentioned a custom function which works for me so please check it that the below custom function is ok or not?

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated: %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="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );
    Leo

    (@leohsiang)

    I just tested that the code in my install and it worked for me.

    What issues are you having?

    Thread Starter Shivam Pandey

    (@wikihelp360)

    Leo, can you please share a custom function to show the last updated date in GeneratePress? Because earlier you shared a custom function which was not working on my website. The custom function given below is working for me, but I have some doubts about it. I copied it from a website and made some changes to it as well. Can you please check, is the below custom function code is okay or not?

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published: %2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated: %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="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );
    Leo

    (@leohsiang)

    Looks ok to me.

    I’m still seeing the updated date in your site as well ??

    Musa_Jutt

    (@musa_jutt)

    Hello Leo, i think you can help me here, i hate coding, i just need your instruction for my site (gotennisracquets.comgotennisracquets.com), if i copy/paste the same code on my site to show the last updated post date?

    David

    (@diggeddy)

    Hi @musa_jutt – yes that code can be applied to your site.

    Musa_Jutt

    (@musa_jutt)

    Thank you David, can you please tell me in which file i have to paste this code?

    Leo

    (@leohsiang)

    We actually have a filter for this now:
    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    The code can be added using one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Code Snippets is the easiest solution if you aren’t using a child theme already.

    Let me know ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to Show Last Updated Date in GeneratePress Theme?’ is closed to new replies.