-1

I want to read the URL and set og tags according to the result I get.

I'm trying document.write but Facebook doesn't see them

Example:

<head>
  <script>
    if(a==b){
      document.write('<meta property="og:title" content="Wow... A equals B, who knew!" />');
    }
  </script>
</head>

Is there a better way to do this?

1

1 Answer 1

0

Open Graph tags should not be used dynamically, Facebook caches those tags. That being said, the Facebook scraper ignores JavaScript, you would have to add them with a server language. For example, with PHP:

<meta property="og:title" content="<?php echo $title; ?>" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.