I'd like to add gravatar support to my Joomla article. How can I do that?

  • What have you tried? google.com/… – TryHarder Sep 30 '15 at 1:54
  • Johan's answer solved the problem momocho :) I was just surprised why there is no simple solution about gravatar while I googled it (it always returns gravatar extensions result rather than tutorial ) then I created this question. Maybe this will help other later – webchun Sep 30 '15 at 2:24

Take a look at the Gravatar PHP documentation. Basically, you want to generate a URL for the image to be displayed. This URL is based on the users email address, and will of course only work for logged in users.

The following code should give you a starting point:

$user = JFactory::getUser();
$default = "http://www.example.com/default.jpg"; // default image if no gravatar
$size = 40; // 1 - 2048 pixels

$grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $user->email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;

<img src="<?php echo $grav_url; ?>" alt="" />

There are many options available for default image, size, rating etc. See the Gravatar documentation for more info.

As for how to use the code, it depends on what you mean by add gravatar support to my Joomla article. You can build a plugin, create an override, or use a custom HTML module that supports PHP code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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