Facebook’s sharer.php is officially back. Not that most people had stopped using it anyway! Along with the new Share button, you can safely use the sharer.php syntax to create a link that shares a URL on one’s Facebook timeline. As there are still many articles/answers out there that have outdated answers to questions about this, I thought this was worth spreading the news. I’m glad that Facebook’s approach to this no longer has to bring about confusion.

Sharer Un-deprecation

Facebook Sharer Popup Window

For a while (2012-2013?), the official Facebook docs has a message that the share button was being deprecated. The Like button was to somehow take over. When this message appeared, it started to worry some web developers.  Many continued to use the facebook.com/sharer/sharer.php formatted link (with the correct parameters). There didn’t seem to be a simple replacement, besides the Feed Dialog (API usage + an app ID), and what about the thousands of sites out there already using the Sharer syntax?

With the release of the new Share button in November 2013, the documentation has been updated. There is no longer any mention of deprecation, and the sharer.php method will use the newest version:

This new Share Button works with a new version of our web-based Share Dialog. When using the sharer.php method of invoking the Share Dialog, this dialog will also display the new version without any changes required.

And under their FAQ, it says:

Can I use the Share Dialog without using the Share Button?
Yes, although we recommend using the Share button to offer the simplest and most consistent experience for people using your site, you can invoke the Share Dialog using a link:

New Share Button

The design of the Like and Share button designs have been updated. They can also be easily added side-by-side. Those using existing code for the Like button, should automatically see the new design. More at Facebook:

Update: How to Dynamically Insert the Current Page

Some people commenting on this post were asking about how to have the sharer work with the current page. This can be done by:

  1. Getting the current page’s URL using PHP
  2. Using the PHP function urlencode on this URL and printing it after the “u” parameter

The URL encoding is necessary because you are basically sending a URL within a URL, as a parameter in the query string. If you have certain special characters in your URL, then the  browser may think it belongs to the facebook.com URL.

So, here’s how you do it in code:

Comments on this Article

  1. Vivek says:

    Do you know how I can update the sharer.php piece of code to pick up the current URL and replace https%3A%2F%2Fparse.com in the code?

    • Josh says:

      You can use PHP to echo the current URL after the “u” parameter in the link, and it should be encoded to be used in a URL. Try this function and then pass the result through the php function urlencode before displaying it.

      • Stephane says:

        Hi, as I don’t have much technical skills, can you tell me where to put the Function and how to call it through urlencode function? Thanks

        [Second Reply Moved]: Found out how, and it works well, thanks :)

  2. Alexandre says:

    So, we don’t have the option to determine a custom image via this sharer, as we could?

  3. Michela says:

    Thank you so much, you have solved me a problem I had for three years!

    • Josh says:

      https://www.facebook.com/sharer.php redirects to https://www.facebook.com/sharer/sharer.php, so they work the same.

  4. Kevin says:

    Looks like they changed their FAQ, because I can not find anything mentioned in your post on the FB docs. Guess this is the new approch:
    https://www.facebook.com/dialog/share?
    app_id=145634995501895
    &display=popup
    &href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F
    &redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer

    Unfortunately I need to register an app to use this endpoint.

    • Josh says:

      Yeah it looks like the page I was referencing has change dramatically. I wish FB would make up their mind about this. It should still work, but I don’t know what their plans are, and why it was removed from the FAQ.

  5. Nasiru Abdullahi Tanko says:

    Thanks, you solved my Problem!

  6. Creets says:

    Thank you so much for this post. Made it possible to make a custom share bar. <3

Comments are closed.