get_avatar_url()WP 4.2.0

Retrieves the avatar URL.

Used By: get_avatar()
1 time — 0.00008 sec (very fast) | 50000 times — 1.67 sec (fast) | PHP 7.0.8, WP 4.5.3

No Hooks.


String|false. The URL of the avatar on success, false on failure.


get_avatar_url( $id_or_email, $args );
$id_or_email(mixed) (required)
The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, user email, WP_User object, WP_Post object, or WP_Comment object.

Arguments to use instead of the default arguments.

Default: null

  • size(int)
    Height and width of the avatar in pixels.
    Default: 96

  • default(string)
    URL for the default image or a default type. Accepts '404' (return a 404 instead of a default image), 'retro' (8bit), 'RoboHash' (robohash), 'monsterid' (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or 'gravatar_default' (the Gravatar logo).
    Default: value of the 'avatar_default' option, with a fallback of 'mystery'

  • force_default(true|false)
    Whether to always show the default image, never the Gravatar.
    Default: false

  • rating(string)
    What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are judged in that order.
    Default: value of the 'avatar_rating' option

  • scheme(string)
    URL scheme to use. See set_url_scheme() for accepted values.
    Default: null

  • processed_args(array)
    When the function returns, the value will be the processed/sanitized $args plus a "found_avatar" guess. Pass as a reference.
    Default: null



#1 Get the avatar's URL from the user's email

$url = get_avatar_url( '[email protected]', array(
	'size' => 48,
) );


#2 Get the URL of the current user's avatar

$url = get_avatar_url( wp_get_current_user(), array(
	'size' => 48,
) );


#3 Display the avatar picture of the author of the current article [auto-translate]

global $post;
$url = get_avatar_url( $post, "size=24&default=monsterid");
$img = '<img alt="" src="'. $url .'">';
echo $img;

// <img alt="" src="">

#4 Checking if email has an avatar

To check if email has an avatar, you need to process the URL of the gravatar separately. In the parameter default specify 404, then get the URL and try to get a picture from that URL using get_headers(). If the response returns 404, then the email avatar doesn't have one.

// check if email has an avatar
function has_gravatar( $email ){

	$gravatar_url = get_avatar_url( $email, 'default=404' );
	$headers = @ get_headers( $gravatar_url  );

	return ! preg_match('|404|', $headers[0] );

var_dump( has_gravatar('[email protected]') ); // true
var_dump( has_gravatar('[email protected]') ); // false

// the execution time is from 0.1 to 1 second. It is very long - this is an HTTP request.

Such checking of request will slow down loading of the site, but if you really need, you can cache the request somewhere, for example in set_transient().


Since 4.2.0 Introduced.

get_avatar_url() code WP 6.3

function get_avatar_url( $id_or_email, $args = null ) {
	$args = get_avatar_data( $id_or_email, $args );
	return $args['url'];