Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Sayan Datta

    (@infosatech)

    Hi

    You need to edit your theme files. Add this snippet to the end of your child theme’s function.php file:

    function flatsome_posted_on() {
        $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    
        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() )
        );
    
        $type = 'Posted on ';
        if ( function_exists( 'get_the_last_modified_info' ) ) { 
            if ( get_the_time( 'U' ) < get_the_modified_time( 'U' ) ) {
                $time_string = get_the_last_modified_info();
                $type        = 'Updated on ';
            }
        }
    
        $posted_on = $type . '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
    
        $byline = sprintf(
            esc_html_x( 'by %s', 'post author', 'flatsome' ),
            '<span class="meta-author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
        );
    
        echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
    
    }

    This snippet will print Published date by default. If you modify any post, then it will print Modified Date. Don’t forget to configure the plugin settings.

    Thanks!

    Thread Starter sallywp

    (@sallywp)

    Hello,

    Thanks for sending and your quick reply!

    When I try to paste the code, it says syntax error, unexpected ‘=’

    It appears to be referring to this line : $time_string = sprintf( $time_string,

    Is there something I can do to fix this?

    Plugin Author Sayan Datta

    (@infosatech)

    Hi @sallywp

    Try to use this:

    function flatsome_posted_on() {
        $time_string = '<time class="entry-date published" datetime="' . esc_attr( get_the_date( 'c' ) ) . '">' . esc_html( get_the_date() ) . '</time>';
    
        $type = 'Posted on ';
    																			  
        if ( function_exists( 'get_the_last_modified_info' ) ) { 
            if ( get_the_time( 'U' ) < get_the_modified_time( 'U' ) ) {
                $time_string = get_the_last_modified_info();
                $type        = 'Updated on ';
            }
        }
    
        $posted_on = $type . '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
    
        $byline = sprintf(
            esc_html_x( 'by %s', 'post author', 'flatsome' ),
            '<span class="meta-author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
        );
    
        echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
    }

    Thanks!

    Thread Starter sallywp

    (@sallywp)

    Thank you!

    I was able to update the code.

    However, it’s now showing just the ‘updated on’ date. Is it possible to show both the ‘published on’ and the ‘updated on’ date?

    So it would be

    H1 Title
    published on [date]
    last updated on [date] (only if the date is different)

    then the featured image, etc.

    Thanks very much much for your help!

    Plugin Author Sayan Datta

    (@infosatech)

    Replace this line

    $time_string = get_the_last_modified_info();

    With this

    $time_string .= ' | ' . get_the_last_modified_info();

    Thanks!

    Plugin Author Sayan Datta

    (@infosatech)

    Hi @sallywp

    Try to use this and ignore my previous code:

    function flatsome_posted_on() {
        $time_string = '<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() )
        );
    
        $posted_on = 'Posted on ' . '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
    
        if ( function_exists( 'get_the_last_modified_info' ) ) { 
            if ( get_the_time( 'U' ) < get_the_modified_time( 'U' ) ) { // 86400 seconds i.e. 24 hours, set it according to your need
                $posted_on   = $posted_on . ' | Updated on <a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . get_the_last_modified_info() . '</a>';
            }
        }
    
        $byline = sprintf(
            esc_html_x( 'by %s', 'post author', 'flatsome' ),
            '<span class="meta-author vcard"><a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
        );
    
        echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
    }

    Thanks!

    Thread Starter sallywp

    (@sallywp)

    That worked PERFECTLY. Thank you so much!

    Thread Starter sallywp

    (@sallywp)

    I’m marking this as resolved. Again, thanks for your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show ‘Last updated date’ below H1’ is closed to new replies.