黄聪:wordpress如何使用get_avatar禁止调用gravatar头像,替换为自定义头像

时间:2023-01-16 06:11:12
add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 );
function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt) {
    
    if ( ! empty( $id_or_email->user_id ) ) {
        $avatar = "http://static.cnblogs.com/images/logo_small.gif";
    }else{
        $avatar = "http://static.cnblogs.com/images/logo_small.gif";
    }
    $avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";

    return $avatar;
}