How to Get the Favicon Image of a Website with Google

The images that you see next to blog comments here are not the regular gravatar pictures, instead they are favicons pulled from the website or blog of the person who has written that comment. The favicons often match the official logo of a website and thus, with these favicon images, you can easily figure out which website a link is pointing to?

How to Get Favicons with Google

Google Shared Stuff (S2) offers a secret URL that can automatically pull the favicon image of any website provided you know the URL of any page on that websites. The images are in the PNG format (not ICO) and hence will render correctly in all browsers using the <img> tag.

The syntax for favicons is google.com/s2/favicons?domain=abc.com where you need to replace abc.com with the full URL of the actual website.

For instance, if the site address is https://www.labnol.org, the URL of favicon image will be:

www.google.com/s2/favicons?domain=www.labnol.org

Now that you know the basics, try this WordPress plugin I wrote to make it easier for you to integrate favicons in your blog comments.

Here’s the internal PHP code that add Google favicon images to your comments:

if (!empty($comment->comment_author_url)) {
  $url = preg_replace('/^https?:\\/\\//', '', $comment->comment_author_url);
  if ($url != "") {
    $imgurl = "https://www.google.com/s2/favicons?domain=" . $url;
    echo '![](' . $imgurl . ')';
  }
}

This gets slightly complex if you are on the Classic Template of old blogger since the authorURL is not directly available and you may require some JavaScript manipulation to get the URL from <$BlogCommentAuthor$>.

However in the new version of Blogger, you can get the URL of the commenter directly using the authorUrl Data Tag so the above technique can be ported to the new Blogger.

And if you have not added a favicon to your blog yet, check this guide on how to add favicons.

Amit Agarwal is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻