UPDATE — For Facebook, use:
<meta property="og:image" content="http://website.com/images/icon.png" />
From the title of this article it may not be immediately understandable what it’s about, but plenty of people are looking for this solution.
Many have asked how do I set the image for sharing links? They are referring to social sites like Facebook, Twitter, etc. when someone chooses to share an article of yours from your website there is an opportunity to share a thumb with the post. What the social websites do is scrape the page for a selection of images, sometimes that’s enough, sometimes it doesn’t serve up any related or quality images.
Since images spark the eye more than just text, which could lead to a click-through to your website, naturally it would be beneficial to have relevant thumbs go out with these shares.
So how can you control this? There isn’t really any special code to define social thumbs (yet anyway that I know of). Well, we’ve learned that these sites just scrape the page for whatever images are available and serve them up. Okay, so then it’s just as easy as posting the image you want to be used at the very top of the page, right? Well yes… that would work, but it’s not always desired to post this image on your actual page for visitors to see while reading.
So, with a little HTML and CSS, we can set an image to be picked up by social websites, but remain hidden to visitors on the website and here’s how:
HTML
<img src="http://website.com/images/some-thumb.png" alt="Website Name" class="hide" />
(you’ll want to paste this in just below the <body> tag of the page you want and I recommend using the absolute URL path for the image)
CSS
.hide{display:none}
(drop in your stylesheet)
OR Use a Quick & Dirty One-off
<img src="http://website.com/images/some-thumb.png" alt="Website Name" style="display:none" />
(again you’ll want to paste just below the <body> tag)
Now this will load it up for social site robots to scrape and collect, but will remain hidden to your users and not interfere with your design.
UPDATE — Another trick to test out as well for Facebook is:
<link rel="image_src" href="http://website.com/images/some-thumb.png" />
(should be added between your <head> … </head> tags — doubling this up with my custom solution below should cover it)
For WordPress users, here’s a plugin.