I want to show author avatar in post info. So I use

<?php echo get_avatar( get_the_author_meta( 'ID' ) , 80); ?>

But how can I check if user has avatar?


get_avatar() returns An img element for the user's avatar or false on failure. The function does not output anything; you have to echo the return value.

so you can try something like that

if( get_avatar( get_the_author_meta( 'ID' ) ) == 0) {
   // no img code
} else {
   echo get_avatar( get_the_author_meta( 'ID' ) , 80 );
| improve this answer | |

this should do what you need:

if( get_avatar( get_current_user_id() ) ){
    echo get_avatar( get_current_user_id() , '64' );
    echo '<img alt="no-image" src="https://image.flaticon.com/icons/svg/149/149071.svg" class="avatar avatar-64 photo" height="64" width="64">';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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