Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Image for Facebook Opengraph og:image meta tag

I am trying to share an image from my website on facebook. The image can be dynamic, but other meta will remain the same.

Is there a way I can have dynamic data in OG:IMAGE tag, or will I have to go with the other option of FB Post APIs.

like image 229
Ankur Avatar asked Apr 05 '13 10:04

Ankur


People also ask

How do I make an image OG 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.

What is the meta data OG image for?

The 'og:' in your website's HTML code stands for 'Open Graph'. It is an acronym of an Open Graph protocol which enables you to tell Facebook how your shared content should be displayed.

What size should Og image be?

The most frequently recommended resolution for an OG image is 1200 pixels x 627 pixels (1.91/1 ratio). At this size, your thumbnail will be big and stand out from the crowd. Just don't exceed the 5MB size limit.

What is an Opengraph image?

An open graph image or OG image is the image that appears when you post a link to a web page or video content on your social media page. This forms part of an important group of meta tags that directly impact how the content links perform on social media platforms, like Facebook, LinkedIn and Twitter.


1 Answers

Yes and no. Facebook scrapes your site once, and cached the metadata that it finds, unless you specifically go here and force the scraper to crawl your site again. The cache does generally expire (perhaps after 1-2 days?), so when requested again outside of this cache period, Facebook will crawl the site again.

You can have a dynamically generated og:image meta tag, but it will only be read the one time (per cache period), and only that instance of the image will be saved.

For example, if user A shares your page, and your page returns imageA.png in the og:image tag, then that is the image that will be associated with your page's metadata.

If user B then shares the same page within the same cache period, Facebook will forgo the metadata scraping and assume that imageA.png is still a valid og:image.

like image 68
Julian H. Lam Avatar answered Sep 28 '22 12:09

Julian H. Lam