Set custom image in FB.ui Facebook Share Dialog in v2.10+

Since Facebook Javascript API removed the picture parameter in v2.10 and 2.9 was shut down on July 17 2017 there’s no easy way to share an image with a link back to your page.

Facebook will always use your og:image no matter what you provide in FB.ui parameters.

Share an image with Javascript API 2.10

Here is my workaround:

  • I append the desired image as an URL parameter
  • Then I use filters from WordPress SEO by Yoast to write the Open Graph meta data according to the URL parameter
  • Facebook detect’s each of the URLs as individual page so it has to scrape each one individually

Here is my HTML Code: a wrapper containing the image and a share button:

<div class="my-image-container">
    <img src="">
    <a href="#" class="fb-share-image">Share</a>');

In my Javascript code I simply get the page url and the image url ans put them together with URL parameter og_img

window.fbAsyncInit = function() {
        appId            : 'YOUR APP ID',
        status           : true,
        cookie           : true,
        version          : 'v2.10'                
    $( '.fb-share-image' ).click(function(e){
        var image = $(this).siblings('img').attr('src');

                    method: 'share',
                    href: $(location).attr('href') + '?og_img=' + image,
                function (response) {


(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); = id;
    js.src = "//";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Facebook gets a separate URL for each of my images now.

The next step ist to customize the Open Graph data according to the URL parameter. I use WP SEO by Yoast but you could also output the OG data manually.

Add this to your functions.php

// functions.php
add_filter('wpseo_opengraph_image',function( $img ){
    if( array_key_exists( 'og_img', $_GET ) )
        return $_GET['og_img'];
    return $img;

add_filter('wpseo_opengraph_url',function( $url ){
    if( array_key_exists( 'og_img', $_GET ) )
        return $url . '?og_img=' . $_GET['og_img'];
    return $url;

Note: You should not use a share-counter on this page because when each image has its own URL your base URL share counter wont increase.


5 Responses to “Set custom image in FB.ui Facebook Share Dialog in v2.10+”

  1. Adam

    Have you tried setting image width and height?

    those action_properties don’t seem to be respected;(

    ‘og:image:width’: ‘1200’,
    ‘og:image:height’: ‘622’

    • hannes

      I haven’t tried. The solution above works good enough for my use case.

    • Rod

      Has anyone tried using a full with image instead of a left hand image? Does a full width image work?


Leave a Reply