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.

This entry was posted in codeigniter and tagged , , , , . Bookmark the permalink.

2 Responses to codeigniter: facebook social plugin – like button helper

  1. Yadheen Raj says:

    I used your simple code and you can see the fb integration in the below url.

    http://www.exploreinsta.com/view/377225224452406733_143699958

    Thanks for your great tips and expecting other Social Network plugin integration also.

  2. Thọ Hoàng says:

    Thanks you very much.
    I done and success with your tutorial.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>