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.
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:
- Getting the current page’s URL using PHP
- 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.