Set Gravatar as Favicon in Your WordPress Blog

Print View Mobile View

WordPress LogoYou might have seen how Tumblr uses a blog author’s Gravatar as the blog’s favicon. Now if you’d like the same functionality in your WordPress blog without any plugin, drop this little snippet to the default theme’s functions.php file.

function GravatarAsFavicon() {
	$GetTheHash = md5(strtolower(trim('[email protected]'))); // your email here
	echo 'http://www.gravatar.com/avatar/' . $GetTheHash . '?s=16'; // favicon size
}

Replace “[email protected]” with your own email address registered on Gravatar.

This code grabs a 16×16 version of your Gravatar. If you want another size, simply replace ‘?s=16‘ with your desired size.

Next, add this to your theme’s header.php file:

<link rel="shortcut icon" href="<?php GravatarAsFavicon(); ?>" />

If you already have a favicon code there, replace it with the above.

With the same function, you can also grab and set the apple touch icon for you site. To do that, first remove ‘?s=16‘ from the earlier function and then add the following to your theme’s header.php file:

<link rel="shortcut icon" href="<?php GravatarAsFavicon(); ?>" />
<link rel="apple-touch-icon" href="<?php GravatarAsFavicon(); ?>">

That’s it! Refresh your blog page to see the new favicon.

via Adam Whitcroft