Yesterday Facebook gave site owners another way of leveraging social media by introducing the ‘Like’ or ‘Recommend’ button. They managed to do it in a way that makes integrating it into most sites a snap. Since I run the WordPress Thesis Theme on a bunch of sites, I set out to integrate the new feature into several of them.
Adding the Like button to Thesis turns out to be fairly straightforward, thanks to the Thesis Hooks system. The problem with the code Facebook provides, however, is that it is specific to a particular URL. Making it work with any blog page is the challenge. The code shown below does the trick.
This solution was created by Ruhani Rabin for generic WordPress installations. Putting the code in the correct place in Thesis was all that was required to enable it.
You’ll want to add the code shown below to your theme’s custom_functions.php file
Add this first bit to the top of the file, where you may already have other actions added:
add_action('thesis_hook_before_post','facebook_like_button');
Then, toward the bottom of the file, where your custom functions would go, add the following:
function facebook_like_button(){
global $post;
?>
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:60px"></iframe>
<?php
}
If you want the button to appear somewhere other than the top of the post, alter the add_action line accordingly, using one of the appropriate Thesis hooks.
UPDATE: For generic WordPress installations or for those not needing the fine grained control Thesis provides, this plugin is probably a quicker, simpler solution.
UPDATE 2: I’ve evaluated the performance of the Like button on three different sites and have concluded the buttons may be wrong for some sites.