Tips & Tricks

Use Gravatar as Favicon

This article will show you the trick to set your Gravatar as your Favicon. So before moving further, have a look at article which show the method to generate Gravatar using PHP.

After following the linked article you should be able to generate your Gravatar using your email address.

We will use same technique to generate gravatar but in addition we will use this generated gravatar as Favicon for website.

Here we will create one function which generates the favicon from the gravatar for both website and apple touch icon.

This function takes two parameter first is your email address and second is the type of favicon you want. Second parameter can be either web or apple.

Let’s have a look at below code:

Code

[cc lang=”php”]
function GetFavicon($email=””,$type=”web”)
{
if($email==””)
$email = “[email protected]”;

$email_hash = md5(strtolower(trim($email)));
$link = “”;
$link.=”http://www.gravatar.com/avatar/”.$email_hash;
if($type == “web”)
$link.=”?s=16″;

echo $link;
}
[/cc]

How to use this?

Once you have placed above function in your code then here is the way how you can use this.

[cc lang=”html”]
” />

” /> “>

[/cc]

Conclusion

Hope you have enjoyed this article. Also now if you want to make you favicon dynamic then just pass the random emails to this function and its done. :)

Subscribe to our RSS Feeds to Keep your self updated.

Shares:
  • Use Gravatar as Favicon | PHP | Syngu
    February 10, 2012 at 12:11 pm

    […] This article will show you the trick to set your Gravatar as your Favicon.    PHP Read the original post on DZone… […]

    Reply
  • Mustafa
    Mustafa
    February 19, 2012 at 9:53 pm

    Its Working good

    Reply
  • Mustafa
    Mustafa
    December 20, 2019 at 2:53 pm

    Its Working good

    Reply
  • mayweather vs cotto
    March 19, 2012 at 9:40 pm

    What an article, I will use gravatar also to enhance my blog

    Reply
  • mayweather vs cotto
    December 20, 2019 at 2:53 pm

    What an article, I will use gravatar also to enhance my blog

    Reply
  • Peter Drinnan
    September 23, 2012 at 5:47 am

    What a great idea. Never thought of doing this but it makes sense now. Also makes it easier to change the icon by just updating at gravatar.com.

    Reply
  • Peter Drinnan
    December 20, 2019 at 2:53 pm

    What a great idea. Never thought of doing this but it makes sense now. Also makes it easier to change the icon by just updating at gravatar.com.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *