如何向我的网站添加缩略图,以便当有人在 Twitter 或 Facebook 上分享 link 时,它会显示图像和 link?

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

如何向我的网站添加缩略图,以便当用户将 link 分享到 Twitter 或 Facebook 时,它会显示 link 以及 HTML 和 [=20] 中的图像=]? 所以我真正想要的是,当用户在任何社交媒体上分享我网站的 link 时,旁边会出现一个缩略图。

我在下面放了一个 link 我想要的东西。

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

Facebook 将寻找

<meta property="og:image" content="http://weekendtrails.com/screenshot.png" />

您可以将此元标记用于 Facebook。我希望它也能与其他网站一起使用

这些被称为 Twitter 卡片,基本上,您将 <meta> 标签添加到您的页面以告诉 Twitter 在它们上显示什么。

我想你要找的卡类型是这个: https://dev.twitter.com/cards/types/summary-large-image

这是一个片段,其中包含示例它是如何工作的(摘自文档):

<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">

他们甚至为您提供验证和预览卡片的服务:
https://cards-dev.twitter.com/validator


对于 Facebook,<meta> 标签不同,此处也有详细记录: https://developers.facebook.com/docs/sharing/best-practices#tags

与 Twitter 一样,他们也提供了一个页面,您可以在其中进行验证和预览: https://developers.facebook.com/tools/debug/

希望对您有所帮助!