|
Wednesday, 05 May 2010 15:29
Add a Facebook Like Button to Your Site in 4 Easy Steps!Written by Chris Jacoby
Facebook is offering up a set of plugins (also known as widgets) and they call them Social Plugins. These plugins can be used on any web page to make that a bit more like Facebook in a way. There is a Like button plugin, a Recommendations plugin that shows what other pages people's friends are reading, an Activity Stream plugin that shows a simplified version of the visitor's personal Facebook news feed, and a Facebook Bar, a toolbar site owners can float at the bottom of the screen that serves all of these things at once. How to add the Like Button plugin onto your site. Step1: Create an Application and Get App ID You will need to create and save your new application on Facebook and save/copy the application ID. Create a Facebook application here. Step2: Build and get XBFML code Customize your like button and copy the XBFML code.
Step3: Load the JavaScript SDK This section is a bit trickier (honestly it's the fun part in all of this) but not hard to accomplish at all. On your web page, anywhere after the tag and before the insert the following code:
//JAVASCRIPT
//script tag
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//close script tag
IMPORTANT: You have to insert your application ID where it says "Your App ID" in the code above. Remember to leave in the quotation marks.
This code will load asynchronously on your site (meaning it will not prohibit the other elements of your site to wait while this script loads). Step 4 (Final Step): Make the Like Button Appear Now that we have generated the necessary code, created an application to get the App ID and added the JavaScript code, we need to make this appear on your web page. Remember the XBFML code you generated in Step 2? Paste it anywhere on your web page you want this to appear. Example:
IMPORTANT: Change "YOUR WEB PAGE URL" to the appropriate URL. Remember to use full syntax URL e.g. http://www.example.com/myblog/
You have now set up your "like button" and should have a similar button (as per the image below) on your website:
If you have any questions or would like clarification on any issue, please leave a comment below.
Internet Explorer Fix: Add 'xmlns:fb="http://www.facebook.com/2008/fbml' to you opening html tag! Further Reading:
To read more about what these plugins are, what they do and how they can help you, please read
Dr. Peter Fish's article: The Quick & Intelligent Guide to Using Facebook's Social Plugins.
Published in
Development Blog
Chris JacobyChris is an Information Systems Engineer who has great experience with the online web world. His strengths lie in website application development, user friendly website design and development, graphics design and website optimization. Nothing is impossible! ~Chris Latest from Chris JacobyAdd comment |

