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.

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Google - WordPress

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
A
Amit Agarwal

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. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account
G

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube