• Resolved Dee

    (@supinda1985)


    Hi,

    How can I change the single post meta from ie:

    April 5, 2022, by [author],

    to

    Written by [author] | Updated on

    ‘Updated on’ should also just reflect the published date if it has not been updated since.

    Thanks in advance.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @supinda1985,

    Try adding this PHP:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    if( ! is_single() ){
    	return $output;
    }
    
    $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">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 );

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

    Then, add this CSS through Appearance > Customize > Additional CSS:

    .single .byline:before {
        content: "Written ";
    }
    .single .byline:after {
        content: "\00a0";
    }
    
    .single .entry-meta {
        display: flex;
    }
    
    .single .entry-meta .byline {
        order: -1;
    }

    Hope this helps!

    Thread Starter Dee

    (@supinda1985)

    Thank you!

    You’re welcome @supinda1985!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘change single post meta (author/date)’ is closed to new replies.