m1crdy
m1crdy

Reputation: 1401

Append dynamic Facebook meta tags to head

I got some variables coming from php to fit in the meta tags of facebook. So I need to append these tags to head with js. I´m doing the following:

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

I see it in debugger but not in "source code view". Also Facebook does not recognize the new generated meta tags. (these tags work if I place them statically).

Could someone help?

Upvotes: 2

Views: 9830

Answers (1)

Tobi
Tobi

Reputation: 31479

The FB crawler doesn't execute Javascript, so this won't work. See

You should have a look at tools like https://prerender.io/ which can statically render dynamic sites.

Upvotes: 6

Related Questions