Showing posts with label Like Button. Show all posts
Showing posts with label Like Button. Show all posts

Sunday, July 25, 2010

WordPress: Add Facebook Like Button using functions.php

The Facebook Like button lets a user share contents with friends on Facebook. When the user clicks the Facebook Like button, a story appears in the user's friends' News Feed, with a link back to the original website.

[caption id="" align="alignnone" caption="Facebook Like Button"][/caption]

Append this code snippet to functions.php file in theme or child theme folder to add the Facebook Like Button.
function add_fb($content) {
$fb = ''; // display only on single page.
if (is_single()) {
$fb = '<iframe src="http://www.facebook.com/plugins/like.php?href=';
$fb .= urlencode(get_permalink(get_the_ID()));
$fb .= '&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;';
$fb .= 'action=like&amp;colorscheme=light"';
$fb .= ' style="border:none; overflow:hidden; width:450px; ';
$fb .= 'height:60px"></iframe>';
}

// display before the content.
return $fb . $content;

// display after the content.
// return $content . $fb;
}

add_filter('the_content', 'add_fb');

Please visit http://developers.facebook.com/docs/reference/plugins/like for more information on how to customize the Like Button.