Add this codeto add FaceBook share option in Magento 2
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $_product){
$proName = $_product->getName();
$proUrl = $_product->getProductUrl();
}
// $_product = $collection->getProduct();
?>
and below add this facebook share icon –>
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($proUrl);?>&t=<?php echo urlencode($proName)?>" onclick='javascript:window.open(this.href,"","width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes");return false' title="Share on facebook">
<!-- <img src="<?php // echo $this->getViewFileUrl('Magento_Catalog::images/facebook-share.jpg'); ?>" alt="Facebook" width="12%"> -->
<span class="fab fa-facebook"></span>
</a>
1 thought on “How to add FaceBook share option in magento 2 ?”
Comments are closed.