I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.
Is there a shortcode or piece of code to do this ?
Thanks for your help
I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.
Is there a shortcode or piece of code to do this ?
Thanks for your help
Share Improve this question asked Sep 10, 2015 at 8:08 Graham SlickGraham Slick 2712 gold badges4 silver badges13 bronze badges 3 |3 Answers
Reset to default 2Display author's avatar and name in single page sidebar. Add this code in sidebar.php or single.php
if ( is_singular( 'post' ) ) {
echo get_avatar( get_the_author_meta( 'user_email' ), 75 );
echo get_the_author_meta( 'display_name' );
}
Here 75 number is the avatar size.
I hope it will help you.
if you are using it in Loop then :
You can display author name by using
<?php $author = get_the_author();
echo $author; ?>
and you can display post author avatar using
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
you can change 32 size to whatever your need.
Hope this will work for you.
thanks
Display author's name and avatar in Post page and single post page sidebar. Put this code in sidebar.php
if(is_home() || is_single()){
echo get_avatar( $post->post_author,'100');
echo get_the_author($post->post_author);
}
I hope useful.
get_queried_object()->post_author
in single page view in the widget to get the post author ID and then take it from there – Pieter Goosen Commented Sep 10, 2015 at 8:22