Creating Custom WordPress Get Avatar Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('get_avatar', 'ajtd_get_avatar', 10, 6); | |
function ajtd_get_avatar($avatar, $id_or_email, $size, $default, $alt) { | |
$args['size'] = (int) $size; | |
$url2x = get_avatar_url($id_or_email, array_merge($args, array('size' => $args['size'] * 2))); | |
$args = get_avatar_data($id_or_email, $args); | |
$url = $args['url']; | |
$class = array('avatar', 'avatar-' . (int) $args['size'], 'photo', 'ajtd-avatar'); | |
$avatar = sprintf( | |
"<img alt='%s' title='%s' itemprop='image' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>", | |
esc_attr($alt), | |
esc_attr($alt), | |
esc_url($url), | |
esc_attr("$url2x 2x"), | |
esc_attr(join( ' ', $class)), | |
(int) $args['height'], | |
(int) $args['width'], | |
$args['extra_attr'] | |
); | |
return $avatar; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment