Last updated: Mon, Apr 17, 2023 10:26 am
Return to Knowledgebase
# | Parameter | Data Type | Required | Description |
---|---|---|---|---|
1 | string | Yes | the email address to generate the Gravatar URL for | |
2 | $s = 120 | integer | No | the size of the Gravatar image in pixels (default: 120) |
3 | $d = 'mm' | string | No | the default image to use if the email address does not have a Gravatar associated with it (default: 'mm' for a mystery man image) |
4 | $r = 'pg' | string | No | the rating of the Gravatar image ('g', 'pg', 'r', or 'x') to determine whether explicit content is allowed (default: 'pg') |
5 | $img = false | bool | No | whether to wrap the Gravatar URL in an <img> tag (default: false) |
6 | $atts = [] | array | No | an array of additional attributes to include in the <img> tag, such as class or alt |
Data Type | Description of Returned Data |
---|---|
string | If $img is false, the function returns a string containing the URL for the Gravatar image.
If $img is true, the function returns an HTML string containing an |
$email = 'example@example.com';
$gravatar_url = get_gravatar($email, 200, 'identicon', 'g', false);
echo $gravatar_url; // output: https://www.gravatar.com/avatar/2d30c67...8?s=200&d=identicon&r=g
$gravatar_html = get_gravatar($email, 200, 'identicon', 'g', true, ['class' => 'avatar']);
echo $gravatar_html; // output: 