How to Add the Facebook Like Button to Your Blog

by Diana Urban on April 22, 2010

Facebook Like Thumbs Up
email

You might have noticed that Facebook has gone a bit “like” crazy this week. One major change affected fan pages: instead of becoming a fan of a page like Coca-Cola, you now “like” the brand. Facebook also introduced a “Like” button that could be added to any page on the internet. This little like button is the easiest way to share content yet. With just one click, a user can share your content with all of his or her Facebook friends.

On Facebook, you can tell your friends if you’re interested in their status updates, posts, photos, or videos by clicking “like.” At the F8 conference this week, Facebook revealed a new social plugin that allows any webpage to add a “like” button and reap the benefits of this viral functionality. Although this new feature is integrated onto Typepad, there isn’t yet a customizable plugin for WordPress. Here’s how to easily add the Facebook like button to any website, including a WordPress blog:

1. Get the Like button code

This is the only code you’ll need to install the Facebook Like button on your WordPress blog. It will automatically detect your post title.

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo
urlencode(get_permalink($post->ID)); ?>&amp;layout=standard&amp;
show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light"
scrolling="no" frameborder="0" allowTransparency="true" style="border:none;
overflow:hidden; width:450px; height:60px"></iframe>

Please note that if you are adding this code to a website OTHER THAN a WordPress blog, use this code instead and customize the “URL.com” for your own domain name:

<iframe src="http://www.facebook.com/plugins/like.php?href=http://URL.com
&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;
colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true"
style="border:none; overflow:hidden; width:450px; height:60px"></iframe>

2. Choose the button type

If you’d like to use the standard Like button, keep the code above the same (layout=standard).

image

If you’d like to use the button count version of the Like button, change “layout=standard” to “layout=button_count”.

image

3. Customize your Like button

There are various customizations you can make to your Like button, all of which you can see on the official like button social plugins page on Facebook’s developer site.

  • Show faces or not: Show faces of your friends with “show_faces=true” or not with “show_faces=false”
  • Like vs. recommend: Have a like button with “action=like” or a recommend button with “action=recommend”
    image
  • Color scheme options: If you have a light color scheme on your webpage, choose the correct contrast with “colorscheme=light”; if you have a dark color scheme, use “colorscheme=dark”
  • Border: Add a border by changing “border:none;” to “border:1px;”

4. Adding the code to WordPress

Adding the Like button to each post

Open your single.php file and look for the_content(). Each theme will be coded differently, but this php call should always appear. I’ve added my code above the the_content() code so the like button appears at the top of my posts. You can choose to add the button below your posts by inserting the code below the_content().

Adding the Like button on your homepage

If you also want the like button to appear above each post on your homepage, like I do here at U Stand Out, open your index.php file and look for the_content(). Just as you did for single.php, add the code above the php code for the_content(). You can also simply add the code to a sidebar widget to give your readers the option to “like” your blog’s homepage.

Let me know if you have any questions in the comments below!

Related Posts:

Article by

Diana Urban (formerly Diana Freedman) is the founder of ustandout.com, a guide for making your web presence stand out using social media and other web marketing tactics. Diana works in advertising as a User Experience Manager at HubSpot in Boston. Start socializing with Diana by following her on Twitter.


Like this post? Want more from U Stand Out? Subscribe via RSS to get updated with all the latest content.


fb-ebook-cta-bottom
  • http://twitter.com/btrandolph @btrandolph

    nice work. very clear.

  • http://twitter.com/btrandolph @btrandolph

    nice work. very clear.

  • http://www.matthewburgess.com/ Matthew

    i get an error :

    The page at http://&lt;?php%20echo%20urlencode(get_permalink($post-&gt;ID));%20?&gt; could not be reached.
    My recent post Green Tea Could Prevent Glaucoma

    • http://www.matthewburgess.com/ Matthew

      fixed it. in Thesis theme, we use OpenHook. And with OpenHook, for any hook there is a check box that says "Execute PHP on this hook". It needed to be checked
      My recent post Green Tea Could Prevent Glaucoma

      • http://intensedebate.com/profiles/dianafreedman dianafreedman

        Ah ok great, good to know! Glad you found the solution. :-)

    • http://intensedebate.com/profiles/dianafreedman dianafreedman

      Hi Matthew! I just went to your most recent post and clicked the "Like" button, and it worked perfectly. Are you still seeing the error?

  • http://www.matthewburgess.com Matthew

    i get an error :

    The page at http://&lt;?php%20echo%20urlencode(get_permalink($post-&gt;ID));%20?&gt; could not be reached.
    My recent post Green Tea Could Prevent Glaucoma

    • http://www.matthewburgess.com Matthew

      fixed it. in Thesis theme, we use OpenHook. And with OpenHook, for any hook there is a check box that says "Execute PHP on this hook". It needed to be checked
      My recent post Green Tea Could Prevent Glaucoma

      • http://intensedebate.com/profiles/dianafreedman dianafreedman

        Ah ok great, good to know! Glad you found the solution. :-)

    • http://intensedebate.com/profiles/dianafreedman dianafreedman

      Hi Matthew! I just went to your most recent post and clicked the "Like" button, and it worked perfectly. Are you still seeing the error?

  • Matthew

    Yes, I fixed it. In the Thesis theme, OpenHook requires you to indicate that php is to be executed in the hook

  • Matthew

    Yes, I fixed it. In the Thesis theme, OpenHook requires you to indicate that php is to be executed in the hook

  • http://twitter.com/btrandolph @btrandolph

    I am using the atahualpa theme, which has a bunch of unique code. I got the button to show up in a post, but it's in the wrong place, and only appears for that post. I have a query in the the gurus (and i don't use that word lightly!) on the bfa forums – I will post when I have the solution.
    My recent post it’s not rocket science, right?

  • http://twitter.com/btrandolph @btrandolph

    I am using the atahualpa theme, which has a bunch of unique code. I got the button to show up in a post, but it's in the wrong place, and only appears for that post. I have a query in the the gurus (and i don't use that word lightly!) on the bfa forums – I will post when I have the solution.
    My recent post it’s not rocket science, right?

  • http://blog.bottomlessinc.com Bottomless

    Here’s the WordPress plugin:
    http://wordpress.org/extend/plugins/like
    No coding necessary, you can customize the look and placement of the button in the settings interface.

  • http://rodokmen.ine.sk Marek Rodokmen

    Thank you for great step by step guide to build “Lite it” Facebook button on my page!

  • http://ustandout.com Diana Freedman

    Thanks! I'm trying out your WordPress plugin now; however, the “Admin” feature doesn't seem to be working. I left you a comment on your blog. Looking forward to your reply! :-)

  • http://www.nikolasallenart.com Nikolas Allen

    How am I supposed to read this post with those humongous #@$!!* share icons blocking half of the left column? Insidious!

  • http://ustandout.com Diana Freedman

    Haha… they're not blocking the words, and are no different from the share icons on Mashable. What's your screen resolution?

  • http://www.nikolasallenart.com Nikolas Allen

    Diana, they were blocking the words, but thanks to your inquiry, I messed with screen rezzie, pushed and pulled the browser window and managed to move those mongo mamas off the sweet spot.

    Thanks, now I can actually glean some of the info from your blog! ;)

  • JNothing

    I'm trying to add my recommend button t each blog post in Modx using the snippet/chunks called “ditto”. I'm sure the wordpress code for this is pretty close to what I need. I think the only issue is how it calls up the URL's. Is there anyone out there who can help?

    Thanks :)

  • sharma

    Thanks a Bunch!
    The information was very precise and useful. I had been banging my head for a long time on FB Help centre and other blog sites but never got a clear idea until I read this post by you. Thanks again!

  • http://ustandout.com Diana Freedman

    And now that I've changed the blog layout, it's not an issue anymore! :-)

  • http://www.nikolasallenart.com Nikolas Allen

    Nice! Looks good Diana. Works better in my browser, too.

    Thanks for the update!

    @nikolas_allen

  • lanethsffarlenn

    Thank you so much! I tried 5 plugins and even tried to manually enter the code, however I could not get any custom stylings to take – your plugin has helped save my sanity!

  • http://ustandout.com Diana Freedman

    You're welcome! I've tried the plugins as well, but manually entering the code instead definitely offers the best results. Glad I could help! :-)

  • james Roughton

    This is one of the greatest website sites that I visit. The tutorials and information provided here are great and useful for anyone.

    Thanks for a great site.

  • http://backgroundfinder.com/ people searches

    As the Facebook button is a button you can click on a look almost all the content on Facebook. This could be a friend to photograph a friend comment is made, or even a group or application.

  • Jai

    nice post Diana. I was wondering if one can customize an image instead of what’s there. i.e. instead of layout=standard to some image button

  • Josie_maletsb

    How do I add a border to the standard facebook like plugin? I followed the “Border;1px” above, but it didn’t do anything!

  • Emmas bucket list

    I just tried, and cant seem to make the like button appear in the sidebar of my homepage… It just shows as text… I typed this in: 

  • Anonnny

    Your code does not work. It displays the buttons, etc, but does not detect I am already logged into FB. When I click LIKE, it takes me to a blank page with the FB logo up top. Obviously this is no longer the correct way to add this functionality to a site.

Previous post:

Next post: