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

Written by Amit Agarwal on Feb 13, 2017

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?

tech-river

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 '<img src="' . $imgurl . '" width="16" height="16" />';	
  }
}

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.

Document Studio

Generate beautiful and pixel-perfect documents in PDF, Word, Excel or PowerPoint.

Download New
Mail Merge

Send personalized emails from Gmail, include unique attachments, track opens and more.

Download Popular
Save Emails

Download email messages and file attachments from Gmail to your Google Drive.

Download Popular

Subscribe to our Email Newsletter