[Support request] Modified date is earlier than posted date when scheduling posts

Home Forums Support [Support request] Modified date is earlier than posted date when scheduling posts

Home Forums Support Modified date is earlier than posted date when scheduling posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1619721
    Ingrid

    Hi!
    I am displaying the published and modified dates in all my posts using the code bellow:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" >%2$s</time>';
    
        if ( get_the_date() !== get_the_modified_date() ) {
            $time_string = 'Sist oppdatert: <time class="entry-date updated-date" datetime="%3$s">%4$s</time><time class="entry-date published" datetime="%1$s">%2$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 );

    The problem is that when scheduling a post it shows the modified date earlier than the published date, for example if I schedule a post for a week from now, it will show like this:

    last modified 15 jan 2021 / published 22 jan 2021

    How can I make the modified date show only if the date is later than the posted date?

    thanks!

    #1620508
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This filter may be better than that one: https://docs.generatepress.com/article/generate_post_date_show_updated_only/

    It will display the updated date only if it’s later than the published date. The only change you may need to make is adding the Sist oppdatert: text using some CSS:

    .updated-date:before {
        content: "Sist oppdatert: ";
    }
    #1626192
    Ingrid

    Thanks Tom, but this function adds only the updated date, I wanted to have both published and updated date ONLY if the updated date is older than the published date.

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