社交分享的默认网站图片

78

我能否设置一个默认的图片来在分享我的网站至Facebook时使用?我注意到Facebook通常会从网站中获取第一张图片作为缩略图。

6个回答

109
您需要设置开放图谱图像元标签:
<meta property="og:image" content="http://example.com/logo.jpg">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1024">
<meta property="og:image:height" content="1024">

了解更多信息,请查看文档


3
我使用了这种方法,但它仍然从我的网站随机选择一张图片? - Rossco
1
我同意 - 仍在等待答案。只是在我的网站上随机选择了一些图片... - Andy
5
根据 linked-in 的说明,你只需要使用 og:image 标签即可。也许你现在看到的图片是缓存的,这个缓存会持续7天。 - Patsy Issa
10
@Rossco,您需要清除Facebook缓存中针对您网站的缓存。 - full_prog_full
8
不是“Facebook图像元标记”,而是由基本上所有社交媒体网站支持的协议。这篇文章让我误以为这种方法只适用于Facebook,但进一步的研究表明并非如此。 - Mark Amery
显示剩余4条评论

16

像这样在 HTML 文档的 <head> 中设置一个 og:image

<meta property="og:image" content="http://example.com/ogp.jpg" />

这是 Open Graph Protocol 的一部分,至少被以下社交媒体网站所认可:

(... 可能还有很多其他的社交媒体网站。)

除了设置上述标签外,您可能还想:


14
<meta property="og:image" content="http://example.com/lamb-full.jpg">
<meta property="og:image:type" content="image/jpeg">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">

图片尺寸应至少为200px X 200px


好的。所有共享链接的站点的默认值是什么?这只是Facebook API吗? - JoshYates1980
1
@JoshYates1980 请查看 https://dev59.com/42kv5IYBdhLWcg3wtTG7 以获取更多使用Open Graph的网站。 - Felix Geenen

11

这是我的解决方案,它很有效:

<head>
    <!--FACEBOOK-->
    <meta property="og:image" content="https://www.website.com/logo.jpg">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:width" content="1024">
    <meta property="og:image:height" content="1024">
    <meta property="og:type" content="website" />
    <meta property="og:url" content="https://www.website.com/"/>
    <meta property="og:title" content="Website title" />
    <meta property="og:description" content="Website description." />
<head>

您可以使用Facebook调试网站进行测试。


8
Facebook的服务器会'扫描'您的网站,以寻找用于共享的图像。如果您想指定要使用的图像,请将其放在您网站的<head></head>部分中:

  • <meta property="og:image" content="http://url-to-your-image.png">

Facebook可能缓存了先前随机图像的副本。要让Facebook重新获取,请点击以下链接:


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接