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

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

0

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

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

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

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

We will never send any spam emails. Promise.