WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have modified the loop.php file to add some comment stuff in. I wanted to show a comment off a link which is working just fine. Now I went to make that comment show more detail by putting the author avatar. So my code looks like this. It does display the default avatar but is should display my image which it is not.

 $comments = get_comments( array(
    'post_id' => $post->ID,
    'number'  => '1' 
 ) );
foreach ( $comments as $comment ) {
    echo get_avatar( get_the_author_meta( 'ID'), 32 );
    echo $comment->comment_author . ' says: ';
    echo '<hr />';
    echo $comment->comment_content;
share|improve this question
About the question What exact part should display your default image and how did you add a default image? Formatting & the WYSIWG editor: Jamie, please take care about formatting. You want an answer, so please take your time to format your question as well as possible. Thanks. – kaiser Sep 22 '12 at 21:38
I will do my best to improve my formatting and details in my questions from now on. – Jamie Sep 23 '12 at 2:50
up vote 0 down vote accepted

The get_the_author_meta function gets the Post's author ID, not the comment-author's information.

The get_avatar() function is perfectly capable of accepting the comment object whole and working it out from that all by itself. So just call it like so:

echo get_avatar( $comment, 32 );

share|improve this answer
Not, that the question is really clear, but how does this answer "(...)It does display the default avatar but is should display my image which it is not." ? – kaiser Sep 23 '12 at 2:06
it's interesting how sometimes reading the codex and send you off in the wrong direction. This worked. Thank you – Jamie Sep 23 '12 at 2:49
kaiser: Sometimes you have to read between the lines. ;) – Otto Sep 23 '12 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.