Search code examples
facebookfacebook-graph-apicachingheadermeta-tags

Facebook Share cache busting to see specified image pull through in the preview


I have read a few thread about Facebook caching the results on your page and also that the Object Graph Debugger will flush this cache if you enter your URL and hit "Fetch New Scrape Information".

I have added this meta tag to the body (so not in the <head>) of my document and the image definitely exists, but the 'Share' feature still shows random images in the preview.

<meta property="og:image" content="http://www.ayrshireminis.com/mini/images/ambanner.jpg" />

Does the OpenGraph meta tags need to be in the <head>?


Solution

  • I have found that, yes, you need to inject it into <head>.

    I do this:

    // inject the Facebook OpenGraph image into the header to allow the FB share functionality to pull in a more relevant image
    var main_image = $('.main_image').attr('src');
    if (main_image) {
        $('head').append("<meta property='og:image' content='" + main_image + "' />");
    }