Magento 2 Social Media – How to Share Product Image and Details on Social Media

magento-2.2.5magento2productsocial-buttons

I want to share product image and details to social media in Magento 2 using addthistool.

We have added http://s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5b30cd59923bb69c js in header part

Phtml

Custom/Module/view/frontend/templates/product/view/social-share.phtml

<div class="st-addthis-custom addthis_toolbox">
<ul class="sharing-links custom_images">
    <li>
        <a class="addthis_button_facebook link-facebook" title="Share on Facebook">
        </a>
    </li>
    <li>
        <a class="addthis_button_twitter link-twitter" title="Share on Twitter">
        </a>
    </li>
    <li>
        <a class="addthis_button_linkedin link-linkedin" title="Share on Linkedin">
        </a>
    </li>
</ul>

Block

Custom/Module/view/layout/frontend/catalog_product_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="content">
        <block class="Magento\Catalog\Block\Product\View" name="product.view.addthis.custom.social-share" template="Custom_Module::product/view/social-share.phtml" before="-" />
    </referenceContainer>
</body>

Best Answer

Facebook reads website og meta tags so you need to add og tags in head of your magento

Example tags:

<meta property="og:title" content="My product title"/>
<meta property="og:site_name" content="ABC Site"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="https://www.example.com/example.html"/>
<meta property="og:image" content="https://www.example.com/media/catalog/product/cache/1/image/265x/9df78eab33525d08d6e5fb8d27136e95/m/k/mke-08-_1_.jpg"/>
<meta property="og:description" content="My product description"/>

Facebook crawler crawls your website and reads these tags from page. And if you want your page to re-crawl then you need to request for re-crawl from this tool:

https://developers.facebook.com/tools/debug/sharing/