I am trying to display user’s avatar/profile image when logged in, but when I use this:

 <?php
    global $current_user;
    get_currentuserinfo();     
    echo get_avatar( $current_user->ID, 64 );

?>

it displays the default_avatar_male.jpg, but I don’t want anything to be displayed unless logged in. Thanks for all help.

2 Answers
2

Hey pass the current user email id in get_avatar() function if user is logged in like this

<?php 
if ( is_user_logged_in() ) {
    $current_user = wp_get_current_user();
    if ( ($current_user instanceof WP_User) ) {
        echo 'Welcome : ' . esc_html( $current_user->display_name );
        echo get_avatar( $current_user->ID, 32 );
    }
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *