附加动态Facebook元标签到头部



我从php得到了一些变量,以适应facebook的元标签。所以我需要用js把这些标签附加到head。我正在做以下事情:

<script>
    $(document).ready(function(){
      console.log("ready");
      $("head").append('<meta property="og:title" content="<?php echo $title; ?>"/><meta property="og:type" content="website"/><meta property="og:image" content="http://www.party-news.de/party/images/termine/flyer/<?php echo $pic ?>"/><meta property="og:description" content="Weitere Events und Bilder auf www.party-news.de"/>');
    });
  </script>

我在调试器中看到它,但不在"源代码视图"中看到。此外,Facebook不识别新生成的元标签。(这些标签工作,如果我把他们静态)。

有人能帮忙吗?

FB爬虫不执行Javascript,所以这不起作用。看到

  • https://developers.facebook.com/docs/sharing/webmasters/crawler
  • https://developers.facebook.com/docs/sharing/best-practices

你应该看看像https://prerender.io/这样的工具,它可以静态地呈现动态站点。

最新更新