0

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?

1 Answer 1

1

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 );
}
1
  • Downvote, doesn't work $output = ( get_avatar( get_the_author_meta( 'email' ) ) == 0) ? et_divi_post_meta() : et_divi_post_meta_custom(); Commented Feb 3, 2022 at 17:08

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.