加载页面后为Facebook共享按钮添加打开图元标记 [英] Add Open Graph Meta Tag After Page is Loaded, for Facebook Share button

查看:81
本文介绍了加载页面后为Facebook共享按钮添加打开图元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为页面分配缩略图:

I have to assign a thumbnail to the page:

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

但是,由于该站点是WordPress网站,因此在加载正文时会加载缩略图的信息(这是WordPress页面).因此,我使用以下JS添加标签(受此

However, as the site is a WordPress site, the information of thumbnail is loaded when body is loaded (it is a WordPress page). Therefore, I use the following JS to add the tag (inspired by this question):

<script>
$('head').append('<meta property="og:image" content="http://example.com/example.png" />');
</script>

该标签已成功添加到< head> 中,但是在我单击Facebook Share按钮后,缩略图不显示.确实,Facebook按钮仅评估原始源代码,而不评估修改后的源代码吗?

The tag is successfully added to <head>, but the thumbnail does not display after I click Facebook Share button. Is it true that the Facebook button only evaluate the original source code, instead of the modified source code?

如果是,我该怎么做才能显示"Facebook分享"按钮的缩略图?

If Yes, what can I do to make Facebook Share button's thumbnail appearing ?

仅供参考,这是Facebook分享按钮代码:

FYI, here is the Facebook share button code:

<fb:share-button type="button_count" href="http://example.com"></fb:share-button>

推荐答案

我认为这是不可能的,因为未执行JS代码.请参阅在共享我的URL时Facebook Sharer如何选择图像和其他元数据?

I don't think this is possible, since JS code does not get executed. See How does Facebook Sharer select Images and other metadata when sharing my URL?

我可以使用客户端代码(例如Javascript或jQuery)更新这些元标记吗?否.很像搜索引擎抓取工具,Facebook刮板不会执行脚本,因此无论存在什么元标记下载页面时是用于图像的元标记选择.

Can I update these meta tags with client side code like Javascript or jQuery? No. Much like search engine crawlers, the Facebook scraper does not execute scripts so whatever meta tags are present when the page is downloaded are the meta tags that are used for image selection.

这篇关于加载页面后为Facebook共享按钮添加打开图元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆