Add Facebook share button with counter
This tutorial will show you how to add a Facebook share button to each blog post in a Blogger blog. The button comes with a counter (optional) that shows a live count of how many times a post has been shared -a way to gauge the post popularity.
This button lets people share the containing post without leaving your blog. It will detect the correct post URL regardless of the type of page you are at -be it home page, individual/post page or any other page.
Now let us proceed,
- Go to Template > Edit HTML > Proceed.
- Back up your template.
- Tick the Expand Widget Templates checkbox on top right corner of the template HTML window.
- Find the following code in your HTML, this is the code for your post content:
<data:post.body/>
- Paste the Facebook button code immediately below (after) it:
<!-- Facebook share button Start --> <b:if cond='data:blog.pageType != "static_page"'> <div style='float:left;padding:5px 5px 5px 0;'> <a expr:share_url='data:post.url' href='http://www.facebook.com/sharer.php' name='fb_share' type='box_count'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script> </div> </b:if> <!-- Facebook share button End -->
Update: [July 2010] Add conditional tag to prevent button from appearing on static pages.
- Configure button
Choose the type of button by replacing the value of
type
attribute (in line 4) with the corresponding code below.FB button Code box_count
button_count
button
icon
- Button repositioning
The steps above positioned the button on bottom left of each post. You can change the positioning if you like:- Position it on top of post
Insert the button code before (instead of after)<data:post.body/>
. - Position it on the right
Change thefloat
in line 3 fromleft
toright
.
- Position it on top of post
- Displaying button on static pages
- To also display the button in static pages, remove the conditional tag -code line 2 and 6.
- Preview, you should see the button appear at the end each post.
- If you like what you see then click Save.
Enjoy!
P.S. Having trouble with Facebook picking up wrong description for your shared links? Go to Facebook share showing wrong description –solved! to fix it.
129 comments to "Add Facebook share button with counter"
thanks very simple and easy
@joeknows
You're welcome. Just test-shared your Pagani Zonda post -ok.
good info
thank you. used it at http://kuchingfoodandfun.blogspot.com/
Thank you! Went very smoothly, just like all the great instructions you give us do!
Have a wonderful week!
Laura
@PumpkinButtKitty
My pleasure
Thanks mate!
http://ontime-news.blogspot.com
hi thanks for your help so far, but I have noticed when i share something on FB from my blog it picks up a bit of text from the sidebar which I would prefer it didn't, is it possible to pick what information is shown.
http://mrcclibrarynews.blogspot.com/
@Library News
I'm afraid you don't have any control on what being picked up. But you can opt to remove or replace the text by clicking on it (in the share window).
Hi, do you know how to add this to emails? Specifically the Share counter button? I'm trying to add it but the code has javascript which I'm assuming I can't use for emails/newsletters?
Any help is appreciated.
Thanks!
@hybrid roots
No button, just the link. Add this code in your email:
http://www.facebook.com/share.php?u=APPEND_THE_URL_YOU_WANT_TO_SHARE_HERE
for example:
http://www.facebook.com/share.php?u=http://www.bloggersentral.com/2010/06/add-search-box-in-navigation-bar.html
Is there any way of placing the button along side the other one I have (your tweetmeme-and-counter one)? On my blog it has placed it below, making my posts extra long...
Thanks
@BioGal
I've just noticed you placed the buttons directly in your posts. That's why you're having issues with the button alignment.
Okay here's what you do,
First, put float:left back into both buttons.
Second, insert a line break [br/] (replace "[" with "<" and "]" with ">") before the first button.
Okay, thanks. I didn't have any square brackets [ or ] in the code, so I couldn't replace them. So I tried putting the code (after replacing float:left; twice) directly after the bit that looked like it was about the post footer < d i v c l a s s = ' p o s t - f o o t e r ' >
and it worked!
I may have learned something important about computers today, but since I can't be sure I did the right thing, I don't think it counts! :)
Thanks for your help - it looks a bit mucky - pushing the labels, etc. to the right, but it'll do!
Thanks again.
Hi! I have a question.
I used this fb counter on my blogsite at http://lan441.blogspot.com together with the retweet button with counter. The retweet button is showing the bubble up even if the counter is on "0", however with facebook, it is not showing counter at all, just the share button.
Can you please help me.
I would really appreciate it.
Thanks!
-Lan
@Lan
The count shows up when it reaches 3.
Great! Finally found a way to use exactly what I want, where I want. Thank you!
@Van Dog
I'm glad your quest ended here.
tq².. likes it.. ^_^
@opie @ tok wie
Thanks...and do come again :)
Hi! I have an issue with this button and I'm hoping you have the answer!
I added a share button to my site (geekychichi.blogspot.com) however instead of sharing posts it shares the whole blog. What am I missing?
Thanks for your help!!
@GC
Your code is missing this attribute:
expr:share_url='data:post.url'
please copy the code in full.
Thank you for the quick reply. I've added in the missing bit of code but now instead of sharing the post it is sharing the comments made on the post....how do resolve this?
Thank you!!
@GC
That's weird...and I have no idea why. Anyway it does share the correct url (your post url), albeit with a wrong snippet.
Hi GL,
I use this on my blog www.kubakoya.com. The button shows no number (eventhough the post shared few times) but it only shows them when I click the button (to share). Do you face this?
@Khairi
See reply 16.
I want to share my posts on my facebook page.Not in FB profile.plz guide me how.
www.papergulfjobs.com
@atif
You can't change the button to do that. Import your posts into Facebook page instead.
THanks alot.....
thank you so much, this is my 5th attempt, I tried some other solutions from other web sites. But this one was what I have been looking for. Thanks again...
@dr angel
You're welcome.
@Bidoluhayat
Happy to hear that :)
like the other have said before me, thank you so much! Everything worked a stated. Quick question: Do you have code for adding digg? I really like the look of failblog.org and now thanks to you I have fb and twitter, but I can't find the digg one? I hope you can help :)
@Anonymous
This is the code for Digg, square button. Replace code line 4 with it.
[script type='text/javascript']
digg_url="<data:post.url/]";
[/script]
[script src='http://widgets.digg.com/buttons.js' type='text/javascript'][/script]
[a class="DiggThisButton DiggMedium"][/a]
I believe failblog.org uses their own custom button.
gives me this message when using the digg code:
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Element type "data:post.url" must be followed by either attribute specifications, ">" or "/>".
@Anonymous
From reply #33
digg_url="<data:post.url/]";
should've been
digg_url="[data:post.url/]";
and you need to replace all "[" and "]" with "<" and "<".
very good, thanks! It works great. Just one question though: It looks like I have to add this code to all my seperate pages? The other two twitter & facebook codes added the icon button to every page in my blog after editing the html of the main template. Am I correct in thinking I need to add this digg code to each page seperatly? Thanks!
SORRY TO TAKE UP YOUR TIME, LOL
I have the digg button working on all pages, I forgot to remove the lines #2 & #6. Your a hero! Thank you again :)
@Anonymous
No, just do what The Blogs of My Life (in reply #37) did.
Or is The Blogs of My Life you?
I'm confused :)
The button where u placed is i'd rwally like it...Master teach me hoe to do it?
@dr angel
You mean my homepage-only Facebook share and retweet button?
Hi, I feel stupid asking this, but I have no idea what this means:
"Choose the type of button by replacing the value of type attribute (in line 4) with the corresponding code below."
I know I have to plug-in the code I want, but I don't understand where in line 4 I'm supposed to put it.
Thanks.
@Valerie
This is the default type attribute:
type='box_count'
so you want to replace "box_count" (the value of the attribute) to the one in step 6.
Thanks.
Sorry for the silly questions, I'm still uncomfortable with HTML codes. :~)
My button shares the correct post title and thumbnail but shows text from the first comment instead of text from the post. Any ideas?
@Nancy
This is your lucky day. I have a post just for that :)
Facebook share showing wrong description -solved
Thanks!!! Your code is the one that finally worked after many failed attempts! x
Thanks! but when i click on it it says in the popup: Enter link you want to share, can't i do that automaticly? like for example the twitter button has a href="" tag of like:
href="http://twitter.com/share?url=ID)); ?>&via=wpbeginner&count=horizontal"
Thanks for the code!
@Franchesca
Thanks for leaving a comment :)
@Chris
It's working fine now.
Thanks you, I love this :)
great post,, you're smart!
Hello Greenlava,
greetings !!
I have spent this whole night being awake to put the social networking share buttons in one line adjacent to each other and to put a text "share this" before them. but of no help. u have been always a great help. once again u r requested to help me out to do the same. my blog is droppingdew.blogspot.com
thanking you,
@Yana
You're welcome.
@vibiz
Well if you insist :)
@Pranab
Here is my answer.
Dear Greenlava,
Greetings !
tried your method but it is returning this msg:
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Element type "div" must be followed by either attribute specifications, ">" or "/>".
Please help !
Thanking you.
@Pranab
Looks like you left out a closing div tag.
Hey !! thanks a ton ! Greenlava.. it worked :-)
This tutorial looked great to me, because I want a share-button, not a like-button. (am I right in that a share-button makes it show up on the newsfeed, and like-button only on the persons page?). Anyway, when I have followed the instructions and then choose preview, my blogpage is blank. I can see my header, the background, and the gadgets on the side, but all posts are gone. What could I be doing wrong?
Yey, I managed to install the share-button, thanks!!. However, I would like the like-button as well. How do you combine the two? I tried to just insert the code for the like-button before the share-button (which was already there), but what happaned was that the like-button looked fine, but the share-button had moved to the right, and looked kind of distorted.
@Karin E Jansson
1. Yes that's correct, a Like only appears on a person's profile page, under Recent Activity.
2. To push the Share button down, you need to add clear:none; in code line 3's style attribute (after the padding) of the Share button:
float:left;padding:5px 5px 5px 0;
↓
float:left;padding:5px 5px 5px 0;clear:none;
No, I must be doing something wrong, it still looks the same.
@Karin E Jansson
Ooops clear:none; what the... It should be clear:both;
I need coffee :)
This is what the code looks like when I only have the share-button:
[data:post.body/] [!-- Facebook share button Start --]
[b:if cond='data:blog.pageType != "static_page"']
[div style='float:left;padding: 5px 5px 5px 0;']
[a expr:share_url='data:post.url' href='http://www.facebook.com/sharer.php' name='fb_share' type='button_count']Share[/a}[script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'/}
[/div]
[/b:if]
[!-- Facebook share button Start --]
[div style='clear: both;'/] [!-- clear for photos floats --]
[/div]
and that seems to work just fine, however, I don't know if the "clear for photos" should be there (I don't want photos to show up when people share a post).
When I then copy your code for like-button, insert it before the share-code and add clear:none;, it looks ok, until I remove the line numbers (I'm guessing I'm supose to remove these? Otherwise it says 1 2 3 4 5 6 7 around and near the button). When I remove the numbers, and preview, the share-button has moved to the right side and looks distorted.
So sorry for harrassing you... I tried to start over, removed both buttons and then added them again, but the problem is still the same; the share-button becomes stretched out (vertically). I have removed the like-button, maby I should settle with that...
@Karin E Jansson
You copied the code improperly. You should've clicked the <> icon on top right of the code.
Anyway I've posted the code on Facebook, so you could just copy and paste. It's here.
You are a genius!
Thank you!!!
(A small donation has been made)
@Karin E Jansson
Not a genius just yet.
You need to correct something, go back to the Facebook discussion.
Thanks for the donation :)
Thanks a lot for this tip. its working on my page at www.apnitally.com
Hey. I'm having a problem with the buttons alignment. I want them one on each side, as they are now. But I want a paragraph or two below, so that they don't look glued to the text. (you can check http://ziproblog.blogspot.com)
Oh, and I would like to know how to eliminate that extra space after the post between the buttons and the tags, published, etc. info.
Any tips?
@Logan
You are referring to the Like and Tweet buttons right?
Insert a line break [br/] before the Like code and reduce the iframe height from 100px to 65px.
Thank you so much. I think It did the trick ;)
Thanks for the info. I wanted to add the facebook share button on my real estate website for a while now, and reading this post - I see that it will be more simple than I thought! Do you have also something about google buzz button? with counter as well?
@Real Estate Analysis
Yes I do, here it is: Add Google Buzz button (with counter) below post.
Hi i am trying to use the script to share a post but when i click on the share button it opens up a window but all i get is a box saying Enter the url you want to share but on the top i can see this :
http://www.facebook.com/sharer.php?u=http%3A%2F%2Flocalhost%2Fclients%2Ftom%2Fnutrition-professor-loses-27-pounds-on-twinkie-diet-what-should-we-make-of-it&t=Nutrition%20Professor%20Loses%2027%20Pounds%20on%20Twinkie%20Diet%3A%20What%20Should%20We%20Make%20of%20It%3F%20%C2%AB%20Tom%20Venuto%27s%20Blog&src=sp
Any suggestions and by the way i am also using the like button script as well side by side with the this share button script.
Thank You in advance!!!
@Rupak
The share URL is incorrect. Your URL is:
http://localhost/clients/tom/nutrition-professor-loses-27-pounds-on-twinkie-diet-what-should-we-make-of-it
Is your platform other than Blogger?
Hello,
I have a small problem: I put your code for FB share in my HTML, but the FB button appears on each post box of the home page, but not on the post's page. I would like it to be the other way around. How can I fix this problem?
My blog's address is: http://bijuteriidincristale.blogspot.com
Thank you in advance,
Alina
@Alexis Design
Are you referring to the share button on the sidebar? Try this: Display widget on specific pages in Blogger
hi! i ve added the button but i get this on the share window that pop-up
http://http%3A%2F%2Fstin-kontra.blogspot...
that means that it cant find the link of the post and share it....
you can check it in my blog
http://stin-kontra.blogspot.com
help pls!!
@Anonymous
It's working fine from here.
i know :) thanks for the button :)
It works with my new blogger site. Thanks for the button code!
Very informative post.I tried it and it works.Thanks for sharing the code.
Thanks! So simple. I'm always amazed when these things actually work! : )
When I added the share button on the blog, it shows up okay, but it is showing the same number from the previous blog post and the new blog post. Can it be changed to show only the "shares" for the current blog post?
blog.lifesongleadership.com
@Mimi
It looks like there's something wrong with your code cause the buttons only share the homepage.
Where did you add the code? Did you add it in your posts?
you are doing a great job.. keep it up
Works as you say.Thanks for the html.I will grab your link too and add to my site patrickspestcontrol.org
@Patrick
Thanks, I appreciate it :)
Hi
This is excellent. By the way is there anyway to find out who shared my page?
good, thank you, that helped alot
@Anonymous
I'm afraid you can't.
thank you :) for code I was looking this
nice INFo
I dont have post.body tag. I also tried to add the code in one of the page elements but it doesnt work. I am also using blogger. Where should i place it? Any help. to view the source for an idea, u can follow my blog link. i have added all the rest of the buttons except fb share.
http://thekisscoach.blogspot.com/
thanks
@zee
The code is meant to be added into a Blogger template.
However if you want to add it as a widget (HTML/Javascript widget), you can. Just remove the "expr:share_url='data:post.url'" attribute in code line 4.
thanks for this tuts
Hi
Thank you this was great. I added a single button to the page but this is just what I wanted. Also I did not know you can click on the text in the share window to change it or delete it. The link still works in the title. I saw someone mentioned a retweet button is there such a thing. I added a bunch of neat things today here
http://lthrwood.blogspot.com/
I am not sure how I am supposed to be using the static pages but it seems like the button I added to the top of the blog shows the count for each static page.
Thanks a million
Thanks for your effort on collecting these information's. Very helpful to us.
Thanks man i like it!!!!!
thank you
Thanks. Useful information.
I love the idea of this, but I'm having a small problem. when I preview with this code, the Share button pulls up into the last line of text of each post... any idea how I can fix this? I've added your code right after the line "data:post.body/
Any help is appreciated.
Randy
@Randy
I see you've fixed that by placing the button in post-footer. But now the "x comment:" pulls up.
You can fix that by adding a line break [br/] after the last line of the code (in step 5).
Hello, i tried adding a FB like (and twitter) button and it shows the exact number (27&3) on every single post. Also, i'd prefer to place these buttons at the bottom of the post rather than the top. I was wondering how to fix this or take the buttons out but when i try to, it gives me an error msg. Am i missing something? Pls help! www.enamoreventsblog.com. Thx in advance, Eileen
@EnamorEileen
Looks like you use the default codes for the buttons. For those buttons to work on Blogger multi-post pages, you need custom codes:
Add Facebook Like button to Blogger and Add Twitter tweet button to Blogger posts.
Thanks for the coding
So far so good the Facebook share is not displaying the bubble count? http://www.tricitypsychology.com/shrinkrap/
@kathyjames
The bubble will appear when the count reaches 3.
Hi ,i fallowed your suggestions
my share was working but i unable to display description of page i used meta tag also but was not calling,
how can i display Title and description .
in shared pages
Thanks,
Madhu,
mmakkena@netpeach.com
@Anonymous
Have you read this post?
Facebook share showing wrong description –solved!
thanks, work on my blog
thanks a lot buddy that was really help full
thanks very simple and go ahead
Thank you Greenlava :)
I have "like" buttons on each individual post, the likes show up on Facebook when people click them. Since I added the Share button just now, I noticed that it reflects the same number of "likes" on each post. Is this supposed to happen, or is there a way to differentiate between likes and actual shares?
Thanks in advance,
http://mistyfiedmafiawars.blogspot.com/
@Misty Dady
Yup, they do share the same counter, so there's no way to differentiate Likes and Shares.
Thanks for the info. This helped me put a FB share button on my site. Sally
I have been looking for this since then... this is great and the best way to put fb share button.
A real informative blog like this is an exceptionally cool helping resource for a needy information seeker like me! Thanks a lot..
This One is the Top blog in Blogger platform. I ever seen.
thanks for the code . Its work on my site :)
how can i add it in wordpress
Thanks .. It worked !
Great works simple. Thanks
Very Nice Post admin
Worked perfectly.. thanks
I could not find data.post in HTML is there any other way? Please help
I've successfully added the Facebook share button thanks for the post
Awesome Article
Thank you..... :)
Wow, wondеrful blog layout! How long haνe you been blоgging for? уou maԁе bloggіng lοoκ еаsy. The ονеrall look of your websitе іs wоnderful, as well аs the сοntent!
wow. great share button man
Really helpful and insightful information - many thanks!
Post a Comment
We love to hear from you! Leave us a comment.
To ensure proper display, HTML/XML/Javascript need to be escaped first using this escape tool.