Skip to content

PHP code snippet – How to add if condition for avatar image?

<?php
$authorpic = get_the_author_meta('author_pic');
if ($authorpic)
    echo $authorpic; 
else
    echo get_avatar( get_the_author_email(), '80' ); 
?>
  
or 
<?php 
$avatar_url = get_avatar_url( $ID, array( 'size'=>200, 'default'=>'404' ) );

if( getimagesize( $avatar_url ) > 1 )
{
    echo '<img src="'. $avatar_url .'" alt="" class="avatar avatar-200">';
} ?>
See also  How to use font awesome uniin CSS?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.