How can I add a thumbnail to my website so that when someone shares a link on Twitter or Facebook, he shows the image and the link?

advertisements

How do I add a thumbnail to my website so when a user shares the link to Twitter or Facebook it shows the link with the image in HTML and Javascript? So what I exactly want is that when the user shares the link of my website on any social media a thumbnail image comes beside it.

I've put a link of what I want below.

https://twitter.com/Medium/status/634152899132592128


Those are called twitter cards and basically, you add <meta> tags to your page to tell Twitter what to show on them.

I think the type of card you are looking for is this one: https://dev.twitter.com/cards/types/summary-large-image

Here is a snippet with examples how it would work (taken from the docs):

<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@nytimes">
<meta name="twitter:creator" content="@SarahMaslinNir">
<meta name="twitter:title" content="Parade of Fans for Houston’s Funeral">
<meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here.">
<meta name="twitter:image" content="http://graphics8.nytimes.com/images/2012/02/19/us/19whitney-span/19whitney-span-articleLarge.jpg">

They even provide you with a service to validate and preview the cards:
https://cards-dev.twitter.com/validator


For Facebook, the <meta> tags are different and are also well documented here: https://developers.facebook.com/docs/sharing/best-practices#tags

As with Twitter, they also provide a page where you can validate and preview: https://developers.facebook.com/tools/debug/

Hope that helps!