A few weeks ago, I wrote about adding a Tweet button to a self-hosted WordPress blog, and followed up by writing about using a little CSS trickery to align the Tweet buttonÂ (thanks to Alex Coles).Â Whilst I was implementing the Tweet Button, I also went about putting a Facebook Share button on each post.
There are plug-ins to do this for me but why use a plugin when the answer is just a single lines of code in two files within the template?
In the same paragraph as the Tweet button (i.e. styled with the same class), I used this code, generated using the Facebook Share Button generator:
This time, the code is identical for both index.php and single.php as, unfortunately, Facebook doesn’t seem to give me any control over the title of the link (it just takes the
tag from the page). There is another method, using query string parameters in the URL but I chose to stick with Facebook’s recommended method.
Incidentally, I chose to Share, rather than Like (which can be implemented by following these guidelines) because they have subtly different purposes and each is represented in a slightly different manner (as Danny Sullivan describes in his post on the subject). After reading Danny’s post, I agree that Share is best for linking to a single post, whilst Like is more suited to the site as a whole (someone might Like markwilson.it and Share one or more posts from the site).