3

The following code is for the built in Facebook sharer URL construction in Magento's 1.9 RWD theme.

<li>
    <?php $_u = 'p[url]=' . $_productUrl . '&p[images][0]=' . $_productImageUrl . '&p[title]=' . $_productName . '&p[summary]=' . urlencode(trim($_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description'))); ?>
    <a href="<?php echo 'http://www.facebook.com/sharer.php?s=100&' . $_u; ?>" target="_blank" title="<?php echo $this->__('Share on Facebook') ?>" class="link-facebook">
        <?php echo $this->__('Share Facebook') ?>
    </a>
</li>

When sharing a URL though with this Facebook button, the description for the page is including HTML tags. Not only have I tried to strip_tags for the short description, it is actually using the long description even if I replace short description with another attribute. I can't find anything in Mage_Core for this...

It is changing the URL correctly for the &p[summary]= parameter but when you preview the shared URL, it just shows the description along with HTML tags.

Any ideas on how to fix this?

8
  • Hi zigojacko, please accept the answer below if it helped you! Thanks! – Anna Völkl Jan 12 '15 at 20:57
  • It didn't though. The answer didn't solve this issue. – zigojacko Jan 13 '15 at 8:31
  • the answer is correct, sharer.php does not allow additional parameters anymore, only the url. you just need to use open graph tags - see the link to ogp.me in the answer, for example. – luschn Jan 13 '15 at 8:35
  • The OpenGraph metadata was already in place for this site when I posted this question. It wasn't picking up any of the OG tags. Though other default Magento builds, the FB sharer works fine (with the same code as in my question) so the answer isn't the solution to this particular issue (which I can no longer continue debugging / testing on incidentally). – zigojacko Jan 13 '15 at 8:43
  • then you only need to refresh the open graph data in the debugger, but that´s a different problem: developers.facebook.com/tools/debug - facebook caches the open graph data. – luschn Jan 13 '15 at 8:46
4

The sharer will no longer accept custom parameters and facebook will pull the information that is being displayed in the preview the same way that it would appear on facebook as a post, from the url OG meta tags.

Source: https://developers.facebook.com/x/bugs/357750474364812/

The URL is the only possible parameter:

<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $encoded_url; ?>" target="_blank">
    Share this page on Facebook
</a>

Just make sure the Open Graph Tags are correct: http://ogp.me/

Btw, you can also use the Share Button or the Share Dialog, but they don't accept custom parameters either: https://stackoverflow.com/questions/24322221/passing-title-url-and-image-on-share-php-of-facebook

If it does not pick up the correct OG tags, make sure to check out the URL in the Facebook debugger, you can also refresh the tags with it - because they will get cached by Facebook: https://developers.facebook.com/tools/debug/

IMPORTANT: The URL MUST be public, Facebook needs to be able to scrape it!

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.