WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use gravatar image as background image for a button. When i use get_avatar function it returns with height width src parameters.

But i need only gravatar url. I mean like http://gravatar.com/.../...

Can anyone tell me how? Thanks

share|improve this question
up vote 4 down vote accepted

Just generate the URL yourself. It's just a hash of the user's email address.

function get_gravatar_url( $email ) {
    $hash = md5( strtolower( trim ( $email ) ) );
    return 'http://gravatar.com/avatar/' . $hash;

This function requires that you pass the user's email address in ... but you could do anything you need to programatically grab the user's address.

share|improve this answer

Look at how it is implemented here:


Additionally check out the very simple Gravatar API:


You can try to hook into the get_avatar filter and preg_match against the 'src' like so:

add_filter( 'get_avatar', function( $avatar ) {
    if ( preg_match( '# src=\'(.*)\' #U', $avatar, $matches ) )
        $some_globally_accessible_var = $matches[1];
    return $avatar;
} );

The some_globally_accessible_var would be an instance variable or some static variable, global.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.