Big news this week is that Facebook has launched its global Like button feature. This is an excellent way to increase exposure of your BuddyPress site and activity within your community. Nobody can deny the power of Facebook and if Facebook users see this liked item on Facebook, they are more likely to click through to check out your site simply because of their relationship with that person. This is a great way to boost your traffic if your BuddyPress users are also strong Facebook users.
My post was inspired by this one over at Geekosystem.com about how to add the Like button to WordPress posts and pages. Check it out if you want to know how to do that. This post will focus on using it with BuddyPress.
This is what the Like Button does:
The Like button enables users to make connections to your pages and share content back to their friends on Facebook with one click. Since the content is hosted by Facebook, the button can display personalized content whether or not the user has logged into your site. For logged-in Facebook users, the button is personalized to highlight friends who have also liked the page.
Facebook’s developer docs outlines the basics of how to use the button on other websites. So, let’s have some fun putting it to use with BuddyPress:
How to Add the Facebook Like Button to the BuddyPress Activity Stream
The default Like button code is set up to add the button to static pages, so we’re going to add a parameter to it to make our URL dynamic, the way BuddyPress handles activity items. You’ll be adding this to the href= part of the code:
1 |
<?php bp_activity_thread_permalink() ?>
|
So this is what you’ll paste into your child theme’s activity/entry.php file:
1 |
<iframe style="border: none; overflow: hidden; width: 450px; height: px;" src="http://www.facebook.com/plugins/like.php?href=<?php bp_activity_thread_permalink() ?>&layout=standard&show-faces=true&width=450&action=like&font=arial&colorscheme=light" frameborder="0" scrolling="no" width="320" height="240"></iframe>
|
Add it anywhere you want. I think the place it makes the most sense is next to the favorite button inside the activity-meta div, but you can put it wherever you think it looks best. You will also need to add some style to make it sit right with your custom theme. Here’s a screenshot of how it looks in the activity stream after some styling:
Then if you click on the like button, it will show up on a Facebook wall like so:
The link will point back to the permalink of that particular activity item. The great thing about this is that users who are logged into Facebook will be able to see others of their friends who also liked the item, along with their avatars:
How to Add the Facebook Like Button to BuddyPress Profiles
Open your members/single/member-header.php file and add the following:
1 |
<iframe style="border: none; overflow: hidden; width: 450px; height: px;" src="http://www.facebook.com/plugins/like.php?href=<?php bp_user_link() ?>&layout=standard&show-faces=true&width=450&action=like&font=arial&colorscheme=light" frameborder="0" scrolling="no" width="320" height="240"></iframe>
|
I would add it in the #item-header-content div, depending on how much prominence you want to give it. That’s just a recommendation, of course; you can place it wherever you want. It will look something like this:
A Few Extra Notes:
If you want to change the button to say “Recommend” instead, you can do that. Just check out the dev docs on Facebook. Also, there are a few more style options to the button, as well as the choice to include faces or not. The basic Like button is available via a simple iframe you can drop into your page easily. A fuller-featured Like button is available via the XFBML tag and requires you use the JavaScript SDK. The XFBML version allows users to add a comment to their Like as it is posted back to Facebook.
This tutorial is based on the Facebook developer documentation for adding the Like button. If you know of a better way to do this, please leave a note in the comments. If you want to see a demonstration of how this works, click below if you want to recommend this post. :) It will show up on your Facebook activity stream as having recommended this article. ;)





Very nice, thanks againt Sarah
I like this. Thanks for sharing. I think this is really just the very beginning of the Facebook integrations that will be possible with BuddyPress.
Sarah,
Would you adjust the location of the button by putting this in the css?
.connect_widget {
padding:10px;
}
Greg- It just depends on how your site is themed, what child theme you’re using, etc. , depending on where you want the button.
Do you know how to restrict the button only to activity updates that have a reply & favorite option?
Sorry, I thought that the reply button was only for content based activities (updates, posts, forums comments etc).
Ideally I would only add the like button for certain activity items (for example not for new user registrations/friending/group joins etc)
Kunal – You’d have to add some more custom things in there… surround the button with whatever restrictions you have of the scope of the activity. Check out the BP codex and experiment :)
Hi Sarah,
Do you know how I can set this Like button behind the Favorite button on the Daily theme?
http://img.skitch.com/20100423-f76sx4ci37ru383n6ssei8g5yb.jpg
I’m not quite sure how to do that.
Thank you.
You would make the favorite button float left, and that should move it up. If it’s a link add a display: block; to the CSS.
Hi Sarah,
I follow your blog daily, great post, but what about using this with the default theme and positioning it inline with the reply and favorite buttons?
Thanks,
Sara, I have the same problem with Psyber…
Thanks.
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
I use bp_user_link on the members, when looking in the source it looks perfect. However on ALL profiles it says “6 members like this”…. so FV picks it up as the same url….
e.g. look at http://farmvillechicken.com/members/admin/ or any other profile.
can anyone tell me whats wrong?
(crossposted on http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/facebook-like-button-unique-href/#post-53436)
nice article, cheers!
thanks works wonderfully, i have taken it a step further myself by adding it to the forums, but i did have to change the style to button_count because of css issues
Hi! I used this tutorial to add a like button to my buddypress activity stream however I encountered an issue with meta property tags which made the like button generate an error. Here’s how I fixed the issue: http://customwebdesignseo.com/groups/buddypress/
Hi Sarah! I used this code but it’s not working. The like button gets clicked and then gets unclicked in a few seconds giving me an error saying the activity permalink could not be found. Do you know how this can be fixed?
Does Sarah ever reply??
Hi Sarah! The code it´s not working. help us from BRAZIL :)
Still waiting for updates :) Cesar Oliveira from Brazil :)
where in the entry.php is this suppose to go i messed it all up good thing i saved the orignal code on a wordpad doc is there a pluging for non programmers like me to add like or share button to the buddypress activity
Do you have an update for 2013, because it appears facebook iframes no longer works?