How to Get the Favicon Image of a Website with Google S2 Converter

H
Published in: Google - WordPress

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.

Published in: Google - WordPress

Looking for something? Find here!

Meet the Author

Web Geek, Tech Columnist
A
Amit Agarwal

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

Get in touch