Site logo

Archived topic

Edit Enty Meta of Blog Post

7 replies · Started by Johnson on December 21, 2020

Viewing posts 1–8 of 8

Hey,

Trust you're good and doing well!

I want to change the entry meta of each blog post to this form:

By (author gravatar) Author Name / Last Updated: Mar 24, 2016

Any help would be much appreciated!

Thanks!
Johnson

Hi there,

try adding this PHP Snippet:

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(
        'author',
        'date',
    );
} );

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

And then add this CSS:

.byline img {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    position: relative;
    vertical-align: middle;
    margin: 0 10px 0 0;
}

.posted-on {
	border-left: 1px solid #ddd;
	padding-left: 10px;
	margin-left: 10px;
}

Hey David,

Thank you for your quick support.

The author gravatar is a square as you can see from my website (offered in private information). Please offer a circular gravatar

And could you please make it in this form:

By (author gravatar) Author Name / Last Updated: Mar 24, 2016

Thank you very much!
Johnson

I just checked and the Avatar is round - maybe try clearing the browser cache.

Now to update the date add this PHP snippet:

add_filter( 'generate_post_date_show_updated_only', '__return_true' );
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
    return ' | Last updated: ' . $output;
}

Thanks David! The gravatar is wonderful!

Could you please help add "Last Updated" behind the "|"

Thank you so much David! You're a genius!

Glad to be of help

This archived topic is closed to new replies.