WordPress set default custom avatar in comment

0.78K views
no comments
29 Dec 2017 2:57 am

This function I was made specially for my theme which is running in this blog. I made function because Gravatar generate random images on each user’s avatar if user not uploaded real image, this function will not work no localhost so please use domain path eg: domain.com/wp-content/themes/mytheme/images/DefaultAvatar.jpg

function getavatar_src($author_idOrEMAIL=0,$size=50){
    $author_email =$author_idOrEMAIL;
    if(is_numeric($author_idOrEMAIL)){
        $author_email = get_the_author_meta('email',$author_idOrEMAIL);
    }
    $default = get_bloginfo('template_directory')."images/defaultavatar.png";
    return "https://www.gravatar.com/avatar/" . md5( strtolower( trim( $author_email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
}

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>