Sunday, August 22, 2010

Add Facebook Like Box to Your Site

Facebook pages are becoming more and more popular with brands, bands, organisations and celebrities who want to boost their social exposure on the web. Facebook’s social plugins and widgets are a great way to link your Facebook page with your website. Let’s look at how to not only insert the popular Like Box code onto your website, but also how to customize it to fit with your design, and make sure the code correctly validates.

View the Facebook Like Box demo

View the Facebook Like Box demo

Setting up the Like Box widget

First things first, let’s get the basic Like Box widget set up. Log into your Facebook account and click the ‘Edit page’ link on the left side of your page’s profile. Over on the right you’ll see the link ‘Promote with a Like Box‘.

The first thing you’ll need is the ID of your Facebook page. You can find this by checking the URL of most of the links on your page profile.

Enter the size and configure the options of your page, then hit the ‘Get Code’ button. Getting the full potential out of a Like Box takes a lot of time and effort. If you’re looking for a quick solution the iFrame code quickly and easily inserts a box onto your webpage, but don’t expect to be able to customize it too much. If you have an hour or two to spare, copy the XFBML code.

In order to use the FBML code, you’ll need some fancy Javascript SDK. Luckily for those of us who aren’t Javascript Wizards, you can find the code already written out from tutorials on the web. Note: The code here uses the old code rather than the new code, so remember to change that in your snippet.

To get the Javascript method working you’ll also need an API key. To get one, head over to and set up a new application. You can leave most of the details blank, as long as you end up with a key of some sort to insert into the SDK code.

Give the page a test. You should see the box load and display correctly, despite being in the boring default Facebook colours. It’s time to start customizing!

Customizing the Facebook Like Box


Link your CSS stylesheet by adding a new attribute to the code. The ?1 at the end is a requirement and needs changing every time you make changes to the your CSS file, otherwise the old styling will be used from Facebook’s cache. So basically if you make a change and reupload the CSS file, don’t forget to also change the index file to ?2 and so on.

If you’re adding the Facebook Like Box to a WordPress theme, you could use WordPress tags to render out the stylesheet URL.

The Firebug plugin for Firefox makes it easy to edit and customize your Like Box in the browser. This saves plenty of time not having to change the stylesheet identifier and re-upload all the files. Just configure the styling how you wish, then replicate the CSS in your stylesheet.

.fan_box .full_widget {
background: none; border: none;
.fan_box .connections_grid .grid_item {
padding: 0 8px 10px 8px;
.fan_box .connections_grid .grid_item a img {
box-shadow: 0px 0px 10px #333; -moz-box-shadow: 0px 0px 10px #333; -webkit-box-shadow: 0px 0px 10px #333;
.fan_box .connections_grid .grid_item a:hover img {
box-shadow: 0px 3px 10px #333; -moz-box-shadow: 0px 3px 10px #333; -webkit-box-shadow: 0px 3px 10px #333;
.fan_box .full_widget .connect_top {
background: url(;
border-radius: 6px; -moz-border-radius: 6px; -webkit-border-radius: 6px;
.fan_box .connections .connections_grid {
.fan_box .connections {
border-top: none;
padding:15px 0 0;
color: #ccc;
font: italic 21px Georgia;
text-align: center;
text-shadow: 0px 1px 4px #000;
.fan_box .connections {
color: #fff;

.fan_box .connections_grid .grid_item .name {
color: #ccc;
font-size: 11px;
.fan_box .profileimage {
margin: 0;

Here’s the CSS I’ve edited and added to generate the styling used in the demo. Most of the CSS rules clear out the default styling, for example: border: none;, but there’s also some fancy additions such as the CSS3 text-shadow styling.

It’s up to you how far you go with the customization. You could simply remove or change the background and border colours, or completely rearrange the elements into something completely unique.

Fixing the validation errors

The Facebook Like Box now looks great, but the FBML code doesn’t do your webpage validation any favours. Don’t worry, there’s a quick and easy fix for that…

Download the handy Javascript file from The author’s blog is in German, but you can figure out how it’s implemented pretty easily. Basically you need to reference the Facebook Validation Javascript file underneath the FBML code, then wrap the tags with comments. The Javascript will then magically fix those validation errors!

View the Facebook Like Box demo

View the Facebook Like Box demo

No comments:

Post a Comment