I have a php widget, and I need to show the avatar of the current logged in user, and I'm calling this code: <?php echo get_avatar(); ?> But its only outputting the default avatar.

Is there a global I need to add above it?

1 Answer 1


This should work great... in this example i am using wordpress codex so you can comapre:

From Wordpress Codex

<?php echo get_avatar( $id_or_email, $size, $default, $alt ); ?> 

so... Based on that...

This is the code you should embed in the desired location in your theme:

    $size = array(60,60); // this is the size of the avatar
    echo get_avatar( $current_user->user_email, $size, $default, $current_user->display_name );

Hope this helps :)

  • Doesn't seem to change anything. Commented Nov 5, 2011 at 3:50
  • it should work mate.. are you sure you are logged in? hmm.. try to enter this after wp_get_current_user(); --THIS--> echo 'User email: ' . $current_user->user_email . '<br />';
    – Sagive
    Commented Nov 5, 2011 at 4:00
  • nope. not working Commented Nov 5, 2011 at 4:37
  • Noting echoes? not even the plain text meaning 'User email:' i guess your not pasting that code in a place that would result in the apearnce of the thumb niether the text i gave you in order to check...
    – Sagive
    Commented Nov 5, 2011 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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