Use Gravatar as Favicon

  • Avinash
  • 4
  • Feb 08, 2012
  • Tips & Tricks

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

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; }
  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;
  }

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"); ?>">

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.

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:

  • Pingback: Use Gravatar as Favicon | PHP | Syngu

  • Mustafa

    Its Working good

  • http://www.mayweathervscotto.info mayweather vs cotto

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

  • http://www.pdvictor.com Peter Drinnan

    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.