How to Add Facebook Like to Any Post on Your Blog/Site with PHP

Use the following codes and post them to “single.php” file of your theme in the “post” section there where you want the code to appear. The best would be to put the code within a “div” that would have it’s own custom CSS. This will allow you to be more flexible with customizing the social buttons as you would also consider to add G+ and Twitter.

1 <iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;show_faces=false&amp;
2 width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px;">
XFBML:
1 <div id="fb-root"></div>
2 <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="<?php echo get_permalink(); ?>" show_faces="true" width="450"></fb:like>

Subscribe to our Newsletter, and see how you can get analytics from the Facebook Like Button.