Can anyone guide me how can i add social share buttons in Magento 2 ?
-
Where do you want to place share buttons and what do you want to share, like website or product or category?– P SCommented Dec 11, 2017 at 7:05
-
add your share buttons code in a BLOCK and call that block wherever you want to show them– Manoj DeswalCommented Dec 11, 2017 at 7:13
2 Answers
If you want to install extension which are easy to implement then prefer below url it is working
https://marketplace.magento.com/magebuzz-socialshare.html
If you want to do custom code
Refer:-https://www.cloudways.com/blog/add-social-share-buttons-magento-2/
First, configure and register the custom module:
For configuration, create module.xml file in app/code/Magenticians/Mymodule/etc:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magenticians_Mymodule" setup_version="1.0.0"></module>
</config>
For registration, create registration.php in app/code/Magenticians/Mymodule:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magenticians_Mymodule',
__DIR__
);
Override Add to cart file:
Copy addtocart.phtml file from vendor/magento/module-catalog/view/frontend/templates/product/view and paste it to app/code/Magenticians/Mymodule/view/frontend/templates/catalog/product/view.
Then create catalog_product_view.xml file in app/code/Magenticians/Mymodule/view/frontend/layout:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.addtocart">
<action method="setTemplate">
<argument name="template" xsi:type="string">Magenticians_Mymodule::catalog/product/view/addtocart.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Now go to Facebook for Developers and Twitter where you can get their codes which you have to add to your add to cart file.