In my shopping site project, I am trying to share the current link (which is product details page) on Facebook using the following url which is working fine:
<?php
$shareUrl = urlencode($product_url);
?>
<a class="share-button-link" href="<?php echo "https://www.facebook.com/sharer/sharer.php?u=" .$shareUrl; ?>">
Facebook
</a>
The above one is working fine but the title and image of the current sharing link on FB is coming different. I mean the image is present on the current url but I want to show some other image.
Now, the current url has many images and I think, Facebook is selecting a random image from the collection of images and title is based on something else (not sure).
My question is: How to add a specific image and title to the sharing link?
I tried this link but doesn't work for me.
<?php
$product_url=$ _product->getProductUrl();
$shareUrl = urlencode("http://www.example.com/product-a");
$shareTitle = urlencode($_product->getName());
$shareImage = urlencode("http://i.imgur.com/59oQPGZ.jpg");
?>
<a class="share-button-link" href="https://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $shareTitle; ?>&p[url]=<?php echo $shareUrl; ?>&p[summary]=nothing+but+you&p[image]=<?php echo $shareImage; ?>">
Facebook
</a>
I can't use this:
<meta property="og:image" content="http://ia.media-imdb.com/rock.jpg"/>
<meta property="og:image:secure_url" content="https://secure.example.com/ogp.jpg" />
Because the images will change for every product page. (I need change the image dynamically, which is not possible in this case)