Update Facebook Open Graph meta tag through JavaScript
Asked Answered
B

3

24

I'm trying to update the meta content of the Facebook's Open Graph title. I updated the content, but when it published the feed, it's still pulling the old information.

Example:

<meta property="og:title" content="Title 1"/>
    I managed to update to
<meta property="og:title" content="Title 2"/>

When I click on the Facebook Like, it's still pointing the title to "title 1".

How can I make it update?

Burroughs answered 20/6, 2010 at 21:27 Comment(0)
O
34

I'm guessing you figured this out already, but others may have the same problem.

You can't change the Open Graph meta tags with JavaScript after the pageload, as Facebook requests the page from the server again when looking for the meta tags, and so it will not find the updated tags.

Furthermore, I found that Facebook only searches the header for the Open Graph meta tags, so adding them in the body will not work either.

Overwrite answered 6/10, 2010 at 9:37 Comment(0)
S
5

Facebook scrapes pages for meta-data only when it is necessary. After you make changes to the metadata, you need to resubmit the object with the 'scrape' parameter set to 'true' in your POST request.

This is outlined in the Open Graph documentation for updating objects.

Shakitashako answered 18/11, 2011 at 18:53 Comment(0)
N
2

The meta tags are read by Facebook when shared (liked, etc.), so the JavaScript code might not work. You can test using the online debugger.

Noenoel answered 29/8, 2011 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.