[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 .= '&layout=standard&show_faces=false&width=450&';
$fb .= 'action=like&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.
This is great! Now I won't be needing a plugin for this. Thanks for the snipppet!
ReplyDeleteSo how do I change the language of the like button in this function?
ReplyDeleteThanks in advance!
@Celina: You can append locale=nb_NO to variable $fb to change the language (locale) of the Like button to Norwegian (bokmal).
ReplyDeleteIt works wonders, thank you so much!
ReplyDeleteI also want the like button on Single Page. What can I do?
ReplyDelete