Site logo

Archived topic

How to set this place as "Last updated"

5 replies · Started by Trạng on September 19, 2022

Viewing posts 1–6 of 6

Hi there, I want to set the default post date into the text "Last updated" like this screenshot

The site in example using Marketer "site library template". So in case I want to use the "Scribe" template in site library how can I set it?

Hi Trang,

The site you linked is using the updated date.

Scribe template is using a block element - page hero for the single posts, the post date can be switched to the updated date easily within the block element like this:
https://www.screencast.com/t/mg9jB40ZtMcw

Hi Ying, thank you.

But what if I don't want to use the "page hero block element" that's available on Scribe and only want to use simple title & updated date like the site in sample? Can you advice? Thank Ying :)

Hi Trang,

You can use a Filter. Try adding this Snippet:

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 );

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Thank Fernado, I will try & give a feedback later! Nice day, friend!

You're welcome Trang! Nice day to you as well!

This archived topic is closed to new replies.