- This topic has 5 replies, 2 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
April 7, 2020 at 6:55 pm #1230607Subhabrata
I want to display the following on each of my blog posts.
“Originally Published On: <Date with Link> and Last Updated On: <Date with Link> by <Author Name> and <Profile Image>
How to do that?
April 8, 2020 at 7:15 am #1231189DavidStaffCustomer SupportHi there,
first off add this PHP Snippet to your site:
add_filter( 'generate_post_author_output', function() { return sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); } ); add_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'author', ); } );
Once thats done i can look at the CSS required to provide the styling and the labels.
April 9, 2020 at 5:52 am #1232423SubhabrataDone.
Please check now.
It doesn’t give the expected result.
April 9, 2020 at 6:54 am #1232492DavidStaffCustomer SupportNow add this:
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 published" datetime="%1$s" itemprop="datePublished">Originally published on: %2$s</time><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 );
And then i can provide some CSS to display all dates and style the avatar etc.
April 9, 2020 at 7:18 am #1232528SubhabrataBetter than previous. But it made author images bigger than needed
April 9, 2020 at 7:31 am #1232534DavidStaffCustomer SupportDid you add the code i provided here:
https://generatepress.com/forums/topic/last-updated-display/#post-1232492I cannot see the changes it should make – if you can add it back ill provide the CSS to style it
-
AuthorPosts
- You must be logged in to reply to this topic.