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:


function GetFavicon($email="",$type="web") { if($email=="") $email = "[email protected]"; $email_hash = md5(strtolower(trim($email))); $link = ""; $link.="".$email_hash; if($type == "web") $link.="?s=16"; echo $link; }
  function GetFavicon($email="",$type="web")
      $email = "[email protected]";
    $email_hash = md5(strtolower(trim($email)));
    $link = "";
    if($type == "web")
    echo $link;

How to use this?

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

" /> " /> ">
  <!-- for web -->
  <link rel="shortcut icon" href="<?php GetFavicon("","web"); ?>" />

  <!-- for apple -->
  <link rel="shortcut icon" href="<?php GetFavicon("","apple"); ?>" />
  <link rel="apple-touch-icon" href="<?php GetFavicon("","apple"); ?>">


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.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: