codeigniter: facebook social plugin – like button helper

Hello everybody,

I have just created a short helper to create facebook like button dynamically for any content, by just giving-in the URL of the page. Hope this one also helps you like my other helpers

Helper function:

1
2
3
4
5
6
7
8
9
10
11
if(!function_exists('facebook_like')){
 function facebook_like($url){
   $formlink  = '<iframe src="http://www.facebook.com/plugins/like.php?href=';
   $formlink .= urlencode($url);
   $formlink .= ';layout=button_count&show_faces=true&width=450&';
   $formlink .= 'action=like&colorscheme=light&height=21" scrolling="no"';
   $formlink .= 'frameborder="0" style="border:none; overflow:hidden;';
   $formlink .= 'width:450px;height:21px;" allowTransparency="true"></iframe>';               
   return $formlink;
  }
 }

Usage:

1
2
3
4
<?php
$url = current_url();
echo facebook_like($url);
?>

Note:
As you can see the function requires you to use the codeigniter’s native URI helper.

Add a Facebook Comment

5 thoughts to “codeigniter: facebook social plugin – like button helper”

Leave a Reply

Your email address will not be published. Required fields are marked *