douxun1407 2013-07-24 07:05
浏览 77
已采纳

加载页面后添加Open Graph元标记,用于Facebook Share按钮

I have to assign a thumbnail to the page:

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

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>

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?

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

FYI, here is the Facebook share button code:

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

1条回答 默认 最新

  • dourang6858 2013-07-24 07:41
    关注

    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?

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?