Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Facebook Open Graph meta tag through JavaScript

Tags:

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?

like image 956
simmu Avatar asked Jun 20 '10 21:06

simmu


People also ask

How do I refresh metadata on Facebook?

You need to ping facebook and notify them to update changes and to do that you can use URL Linter. It may take some time for facebook to update your changes.

How do you add meta tags to Open Graph?

Just go to Page Settings > Social Image > Upload. If you need to add other OG tags and customize the default settings, go to Page Settings > Advanced > Page Header Code Injection. Read the following section on adding the tags manually and copy-paste the code there.

How do I change the OG image to dynamic?

You can change og:image with following code: $('meta[name=og\\:image]'). attr('content', newVideoUrl); But, if you want to change the image permanently (so Facebook can scrape your data and the image will be available for sharing), you need to change this value on the server.


2 Answers

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.

like image 178
Hans Skov Avatar answered Nov 04 '22 14:11

Hans Skov


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.

like image 32
Noah King Avatar answered Nov 04 '22 12:11

Noah King