Site logo

Archived topic

Getting avatar to show next to author name on post pages

10 replies · Started by Kevin Wabiszewski on November 28, 2018

Viewing posts 1–11 of 11

Hi there,

Any chance you can link us to the site in question?

You can edit the original topic and use the private URL field.

Let me know :)

I just tried the exact snippet using Code Snippets plugin and it's working for me:
https://www.screencast.com/t/KQlvkXHpW

So you've added the snippet to the site you linked above and the snippet itself is activated?

Thanks for the quick response. Did you just paste it into the code snippets plugin? Anything else I need to do? Maybe it is because I made the date and author unclickable.

Yup probably. Can you temporarily remove other code and just make sure this one is working?

Yeah that was the problem. Now I need to figure out how to get them to work together haha.

OK try removing everything you have before and just add this:

add_filter( 'generate_post_author_output', 'tu_add_author_gravatar' );
function tu_add_author_gravatar() {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s %5$s<span class="author-name" itemprop="name">%4$s</span></span>',
			__( 'by','generatepress'),
			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_post_date_output','tu_remove_date_link', 10, 2 );
function tu_remove_date_link( $output, $time_string ) {
	printf( '<span class="posted-on">%s</span>',
		$time_string
	);
}

Thanks a lot Leo! I will try that out and let you know if it works.

It worked thanks man!

Glad I could help :)

This archived topic is closed to new replies.