Dynamically changing OG tags

Hi there,

So I’m looking to setup my website which has multiple pages but I want these to be independently shareable on Facebook - this of course (it appears!) means that I need to setup OG tags for the Facebook share button to pick up on.

However, as I will have multiple pages to look after my original thought was to use JavaScript to simply pick up on various elements on the page to populate the OG tags (e.g. title, description, image). After some initial tests I’ve found that the OG tags are not being updated within the source, but I presume that this will also be an issue if Facebook were to pick up on the OG tag details?

Is it possible to use JavaScript to dynamically alter OG tag contents or would this need to be done on the server-side? Does anyone have any other recommendations of how to make my content shareable but the shared content to be specific to each page (e.g. the title and image that’s shared)?

Many thanks in advance!

So after finding the Facebook Sharing Debugger tool, I’ve found that none of the OG values are being changed by the JS - I assume then that this isn’t possible with JS?

I think it’s that Facebook gets the OG data and doesn’t run any DOM changing JavaScript. i.e. Facebook is not a browser.

It might be possible to write some kind of code that runs on a FaceBook page, but I think any dynamic OG data script should run before it’s sent to FaceBook.

If I interpret your question correctly, you can construct the meta tags with JS certainly, but there’s no point really because the way it works the tag has to be present on the page even before the page has loaded. Javascript adds the Meta tag to the page after DOM has loaded. Meta tags have to be on the page or implemented server side.

hope this helps.

2 Likes

Right…that makes sense and as I thought. So it would have to be done on a back-end point of view I would guess?

Thanks also Whittfield - that’s as I thought.

On a slightly different topic, if I were to use JS to populate title attributes on links in a page, would these be used for SEO purposes or would Google etc. discount them as they would be loading after page-load?

Thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.