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)); ?>&layout=standard& show_faces=true&width=450&action=like&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 &layout=standard&show_faces=true&width=450&action=like& 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).
If you’d like to use the button count version of the Like button, change “layout=standard” to “layout=button_count”.
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”

- 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!









{ 35 comments… read them below or add one }
nice work. very clear.
nice work. very clear.
i get an error :
The page at http://<?php%20echo%20urlencode(get_permalink($post->ID));%20?> could not be reached.
My recent post Green Tea Could Prevent Glaucoma
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
Ah ok great, good to know! Glad you found the solution.
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?
i get an error :
The page at http://<?php%20echo%20urlencode(get_permalink($post->ID));%20?> could not be reached.
My recent post Green Tea Could Prevent Glaucoma
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
Ah ok great, good to know! Glad you found the solution.
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?
Yes, I fixed it. In the Thesis theme, OpenHook requires you to indicate that php is to be executed in the hook
Yes, I fixed it. In the Thesis theme, OpenHook requires you to indicate that php is to be executed in the hook
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?
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?
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.
Thank you for great step by step guide to build “Lite it” Facebook button on my page!
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!
How am I supposed to read this post with those humongous #@$!!* share icons blocking half of the left column? Insidious!
Haha… they're not blocking the words, and are no different from the share icons on Mashable. What's your screen resolution?
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!
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
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!
And now that I've changed the blog layout, it's not an issue anymore!
Nice! Looks good Diana. Works better in my browser, too.
Thanks for the update!
@nikolas_allen
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!
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!
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.
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.
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
How do I add a border to the standard facebook like plugin? I followed the “Border;1px” above, but it didn’t do anything!
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:
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.
Great! Keep it up!
Great article Diane can the URL point to each page as well or does it have to be just the domain itself? Must check out the rest of the site for more hints and tips.
Thank you
Colin
Yes, you can have the URL point to each page. If you’re using Wordpress, I’d recommend using a plugin that automatically does this for you.