i want to get the user avatar URL to use it as background URL style for a div. i tried to use the following but it does not return anything when i view the code it appears like that.
background: url()
i used this function.
function get_avatar_url($get_avatar){
preg_match("/src="https://wordpress.stackexchange.com/questions/63198/(.*?)"/i", $get_avatar, $matches);
return $matches[1];
}
any help please??
3 Answers
It’s fairly simple to construct the Gravatar URL yourself, it’s just an MD5 hash of the user’s email address.
<?php $gravatar="http://www.gravatar.com/avatar/" . md5(strtolower($email)) . '&s=32'; ?>
<div class="avatar" style="background: url(<?php echo $gravatar ?>);" ></div>
The s
parameter at the end there defines the size of the image in pixels.
Using Gravatars – WordPress Codex