1

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>

  • @ShoaibMunir i am using addthis.com plugin.But how can i pass product details to facebook or any other social media – Parthavi Mar 12 at 9:44
1

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/

  • I have added meta property as u have defined but when i debug the url unable to get few property such as og:type,og:description,og:image Can u provide me solution for that – Parthavi Mar 12 at 10:35
  • u can check in file vendor\magento\module-catalog\view\frontend\templates\product\view\opengraph/general.phtml it is already set but not displayed in facebook – Parthavi Mar 12 at 10:38
  • is it appearing on website browser source? – Shoaib Munir Mar 12 at 10:46
  • Yes it is appearing – Parthavi Mar 12 at 10:51
  • it should work then, can you share your product url? – Shoaib Munir Mar 12 at 10:54
1

There is a free extension available, You can use it :

https://marketplace.magento.com/magebuzz-socialshare.html

https://www.mageplaza.com/magento-2-social-share/?utm_source=mageplaza&utm_medium=mageplaza&utm_campaign=mageplaza-review&utm_content=Social%20Share

  • Can u explain in detail regarding developer section – Parthavi Mar 12 at 9:50
  • Have you installed the above extension? – Amit Naraniwal Mar 12 at 9:55
  • I am using addthis.com this plugin – Parthavi Mar 12 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.