11

Facebook used to allow custom parameters in the Facebook share button, but it is not working now. What I need is to create a Facebook share button which will have a custom title, url, image, description, etc. It cannot be done using meta tags because there are multiple share buttons on a single page. Each should have a different title, urls, images etc. I heard it can be done using the Facebook app - using app id or something.

I tried this but it's not working:

<a title="send to Facebook" 
  href="http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_SUMMARY&p[url]=YOUR_URL&p[images][0]=YOUR_IMAGE_TO_SHARE_OBJECT"
  target="_blank">
5
  • 1
    <a href="facebook.com/sharer.php?u=<?php echo $pageUrl; ?>" title="Facebook share" ><img style="margin-right: 10px;" src="_images/facebook_share.png" alt="facebook share button"/></a> Apr 5, 2014 at 5:54
  • “It cannot be done using meta tags, because there are a number of share buttons in a single page” – so all of them are sharing the same URL? One URL == one Open Graph object. If you want to use different Open Graph objects, use different URLs. If this is not an option (although sharing the same object with multiple images/descriptions does not make much sense – when those posts are re-shared on FB directly, FB will pull the info from the URL anyways), the Feed dialog still allows you to set those parameters at runtime.
    – CBroe
    Apr 5, 2014 at 12:37
  • urls are different. Or is it possible in PHP to goto another page if the visitor is from facebook @CBroe Apr 5, 2014 at 16:07
  • So if the URLs are different, then why can’t you just provide the individual meta data under each of them? / Facebook appends a certain amount of tracking parameters to links from their news feed, so you could look for these and then redirect if necessary.
    – CBroe
    Apr 5, 2014 at 18:49
  • ooops sorry the urls are the same. I mean the title, description and image will be different. @CBroe Apr 6, 2014 at 1:45

4 Answers 4

6

Unfortunately, it appears that we can't post shares for individual topics or articles within a page. It appears Facebook just wants us to share entire pages (based on url only).

There's also their new share dialog, but even though they claim it can do all of what the old sharer.php could do, that doesn't appear to be true.

And here's Facebooks 'best practices' for sharing.

1
5

This is the code as 2017:

<i class="fa fa-facebook-square"></i>
<a href="#" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),'facebook-share-dialog','width=626,height=436');return false;">Share on Facebook</a>

Facebook now takes all data from OG metatags.

NOTE: This code assumes you have OG metatags on in site's code.

Source

5

Use facebook feed dialog instead of share dialog.

Example:

https://www.facebook.com/dialog/feed?app_id=1389892087910588 &redirect_uri=https://scotch.io &link=https://scotch.io &picture=http://placekitten.com/500/500 &caption=This%20is%20the%20caption &description=This%20is%20the%20description

3
2

Crude, but it works on our system:

<div class="block-share spread-share p-t-md">
  <a href="http://www.facebook.com/share.php?u=http://www.voteleavetakecontrol.org/our_affiliates&title=Farmers+for+Britain+have+made+the+sensible+decision+to+Vote+Leave.+Be+part+of+a+better+future+for+us+all.+Please+share!" 
     target="_blank">
    <button class="btn btn-social btn-facebook">
      <span class="icon icon-facebook">
      </span> 
      Share on Facebook
    </button>
  </a>

  <a href="https://www.facebook.com/FarmersForBritain" target="_blank">
    <button class="btn btn-social btn-facebook">
      <span class="icon icon-facebook">
      </span>
      Like  on Facebook
    </button>
  </a>
</div>
1
  • will there be any error if i use this method in 2018? Nov 9, 2018 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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