Reputation: 759
I've put a Facebook Like button with every product on my list pages in Magento. Here's a screenshot:
I'm having 2 problems:
As far as I can tell, I've setup everything correctly, but maybe I'm missing something. Here's what I've done so far:
In head.phtml I've added these meta tags, which, following Facebook's Open Graph protocol, are supposed to define the correct image and text (I specify the short description, which doesn't contain any HTML tags, instead of the long description):
<?php
$product = Mage::registry('current_product');
if($product)
{
?>
<meta property="og:title" content="<?php echo trim($product->getName()); ?>"/>
<meta property="og:description" content="<?php echo trim($product->getShortDescription()); ?>"/>
<meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>"/>
<meta property="og:type" content="product"/>
<meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'image') ;?>"/>
<?php
}
?>
In header.phtml, I added the script that enables the like button:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
And in list.phtml, I added the button element where I want it to appear, dynamically specifying the URL of the product that's to be liked:
<div class="fb-like" style="display:none;" data-href="<?php echo $_product->getProductUrl() ?>" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
Any ideas of why this isn't working? Thanks.
Upvotes: 0
Views: 2327
Reputation: 17656
You may want to use php strip_tags()
. Take a look at Strip out HTML and Special Characters
E.g.
<meta property="og:description" content="<?php echo strip_tags(trim($product->getShortDescription())); ?>"/>
Upvotes: 1