73

In the setup dialog for the Like-Button, there are only two options for layout:

Unfortunately, the numbers for the website of my employer is nowhere near 22'000, so the powers that be have decided that we should not show the number of "likes" until said number is a little more in our favour. As far as I know, I don't have access to the layout of the button through Javascript or CSS (it's in an iframe served by facebook). Are there any other ways to hide the count?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Benjamin Wohlwend
  • 30,958
  • 11
  • 90
  • 100
  • Can't you use jquery to find the dom element that the like count sits in and remove it? – BeRecursive Sep 15 '10 at 12:51
  • Don't use an iframe at all. Use a static image from your own server. Has the additional benefit of protecting your users privacy. – CodesInChaos Sep 18 '11 at 15:28
  • This page has a solution that worked perfectly for me (using FB code generated in Aug 2012): http://learn-a-lot-everyday.blogspot.com/2012/05/facebook-like-button-without-count.html – bigmac Aug 06 '12 at 19:39
  • 2
    Are we allowed(without restrictions) to manipulate with Like button like this? Can't find any information about that and would like to do so :) – lukas.pukenis Jan 04 '13 at 14:51
  • 1
    [fb privacy policy](https://developers.facebook.com/policy/) IV. Application Integration Points 4 d. You must not obscure or cover elements of our social plugins, such as the Like button or Like box plugin. – Dario Nov 02 '13 at 23:27

15 Answers15

54

If you do overflow:hidden then keep in mind that it will also hide the comment box that comes up in XFBML version... after user likes it. So best if you do this...

/* make the like button smaller */
.fb_edge_widget_with_comment iframe
{
    width:47px !important;
}

/* but make the span that holds the comment box larger */
span.fb_edge_comment_widget.fb_iframe_widget iframe
{
    width:401px !important;
}
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
farooq
  • 887
  • 8
  • 4
  • 4
    Works like a charm. From all the answers, this should be the chosen one. – Dan H Feb 03 '12 at 02:45
  • This is not the best solution for supporting multiple language. – T. Junghans Mar 14 '12 at 14:18
  • 2
    This did it for me (must use the version): `.fb_edge_widget_with_comment>span,.fb_edge_widget_with_comment>span>iframe { width:52px !important; height:24px !important; }` – Nathan J.B. Apr 27 '12 at 02:41
  • it was working fine, but now facebook has introduced the comment box also in same iframe, so iframe size is dynamically increased because of !important its not getting increased so giving weird issue – Techmaster Feb 06 '13 at 11:33
42

The Like button coded to show "Recommend" is 84px wide and the "Like" button is 44px, will save some time for you CSS guys like me who need to hide how unpopular my page currently is! I put this code on top of my homepage, so initially I don't want it to advertise how few Likes I have.

Community
  • 1
  • 1
The Surrican
  • 29,118
  • 24
  • 122
  • 168
  • 2
    If you're using the javascript version of the button, check out my answer below. There's more you need to do now to make sure everything still works correctly. We'll need to keep changing things as Facebook changes -- that is one of the pitfalls of mucking with things that weren't originally meant to be modified. – Akrikos Sep 22 '11 at 17:14
  • have fun not cutting the button off in mobile webkit. – Marcy Sutton Nov 16 '11 at 00:47
  • 9
    This does not take into account the length of the text in different languages. So you might end up cutting the text off. Unless there is a way to fix what language the button is displayed in, but I'm not aware of such a setting. – Emil Stenström Jan 25 '12 at 16:15
  • 2
    you can force the language by specifying the locale when including the script from facebook – The Surrican Jan 27 '12 at 16:59
  • @joe-hopfgartner I was looking for a solution today and your comment solved my problem :) – edelwater Jan 17 '13 at 14:45
42

Accepted answer is good, but be careful with multilingual pages. The text differ in length:

English: Like

Dutch: Vind ik leuk

German: Gefällt mir

Just a heads up.

Bondt
  • 798
  • 9
  • 22
10

It is now officially supported by Facebook. Just select the 'Button' layout.

https://developers.facebook.com/docs/plugins/like-button/

amosmos
  • 1,039
  • 10
  • 20
10

Just encompass the iframe in a div set the width to the width of button, set overflow to hidden i.e.

  <div style="width:52px;overflow:hidden;">
      <fb:like layout="button_count"></fb:like>

      <div id="fb-root"></div>
          <script>
              window.fbAsyncInit = function() {
                  FB.init({
                    appId: 'YOUR_APP_ID',
                    status: true,
                    cookie: true,
                    xfbml: true
                  });
              };
              (function() {
                  var e = document.createElement('script');
                  e.type = 'text/javascript';
                  e.src = document.location.protocol +
                  '//connect.facebook.net/en_US/all.js';
                  e.async = true;
                  document.getElementById('fb-root').appendChild(e);
              }());
          </script>
      </div>
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Silly Rabbit
  • 109
  • 2
  • 2
    this doesn't really work anymore because they've changed the Like button's functionality. i suspect it was partially deliberate to halt this kind of 'behavior' which is likely against terms and conditions. plus watch out because FireBug will complain sometimes if you click on something that is partially hidden as a security measure – Simon_Weaver Sep 15 '10 at 02:50
4

Most of the suggestions are now, no longer valid.

The correct fix as of today, is to use the 'button' layout.

eg. <div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" data-action="like" data-show-faces="true" data-share="false"></div>

Image of button on FB Docs

The FB Docs, seem not to be fully updated yet... if you scroll down you'll see they state only 3 layouts are available, yet the dropdown suggests 4.

enter image description here

This means you can now use a less hacky solution!

kaichanvong
  • 381
  • 3
  • 12
3

If you're using Facebook's javascript like button (so you can capture like events), here's what we had to do:

Due to a change Facebook recently made in the way comment dialogs display, we had to change how we were hiding it. The way they show the comment dialog has been 'moving' the content inside of the my overflow:hidden element so that the button looks really odd to the user after they click the like button.

In addition to adding a wrapping element with an 'overflow:none' style, you will need to hide the comment element that Facebook is putting onto your page:

Styles:

span.no_overflow {
  overflow: none;
  width: 50px;
}

.no_overflow span.fb_edge_comment_widget.fb_iframe_widget {
  display: none;
}

Markup:

<span class="no_overflow">
<fb:like></fb:like>
</span>

We're still using the fb:like markup though. I have not tested this with the new div-based markup that Facebook is providing on their site now.

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Akrikos
  • 3,595
  • 2
  • 24
  • 22
3

I know many solutions have been posted already, but mine is still somewhat different. It works for the HTML5 Version of the like button and only uses css to hide the count box. Don't forget to add the appId to test.

CSS:

<style type="text/css">
    .fb-like span {
        display: block;
        height: 22px;
        overflow: hidden;
        position: relative;
        width: 140px /* set this to fit your needs when support international sites */;
    }

    .fb-like iframe {
        height: 62px;
        overflow: hidden;
        position: absolute;
        top: -41px;
        width: 55px;
    }
</style>

FB Like Button:

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=xxxxxxxxxxxx";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like" data-send="true" data-layout="box_count" data-width="450" data-show-faces="false"></div>
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
T. Junghans
  • 11,385
  • 7
  • 52
  • 75
2

It seems as if FaceBook has recently changed some code - whenever I clicked "Like", the contents jumped to the left, thus messing up the UI. No CSS / JS tricks made it work. I went with a more simple solution, using an iframe.

NOTICE - Though some devices already support iFrames, not all mobile devices do. iFrames are actually old and not recommended at all, but it did the trick for me.

Lets take the default like-generation script from facebook, and generate an iFrame like box;

Click here to generate like button

Go for the "Box_Count" style, with a counter on top.

When you press "Grab the code", go for the iFrame code. You'll get something similar to this;

<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.example.com&amp;send=false&amp;layout=box_count&amp;width=45056&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=90&amp;appId=1234567891011" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:45056px; height:90px;" allowTransparency="true"></iframe>

Now lets wrap a div around there.

<div class="like_wrap">
    <iframe (...)></iframe>
</div>

Give it the following CSS:

.like_wrap {
    width:55px;
    height:25px;
    overflow:hidden;
}

Now you'll probably see the left top corner of the counter. Now we have to fix the iFrame. Give it a class;

<iframe class="like_box" (...)> </iframe>

And make it so that it is always english, by adding "&locale=en_US" to the URL. This is to prevent weird layouts in other countries - in Dutch it would be "Vind ik leuk" and in english "Like". I guess everybody, in every language, knows a "Like" so lets stick with that.

Now we'll add some more CSS for the like_box;

.like_box {
    margin-top:-40px;
}

So the whole code looks like this (i've removed the app_id as I didn't need it)

HTML:

<div class="like_wrap">
    <iframe class="like_box" 
        src="//www.facebook.com/plugins/like.php?href=CURRENT-URL-ENCODED&amp;send=false&amp;layout=box_count&amp;width=45056&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=90&amp;locale=en_US" 
        scrolling="no" 
        frameborder="0" 
        style="border:none; overflow:hidden; width:45056px; height:90px;" 
        allowTransparency="true"></iframe>
</div>

CSS:

.like_wrap {
    width:55px;
    height:25px;
    overflow:hidden; 
}

.like_box {
    margin-top:-40px;
}

And now i have a decent, small, like box, that works fine and doesn't jump around. Let me know how this works out for you and if there are any problems that you are facing.

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Rob
  • 4,927
  • 4
  • 26
  • 41
1

this worked for me:

.fb-like.fb_edge_widget_with_comment.fb_iframe_widget {
    height: 26px;
    overflow: hidden;
    width: 138px;
}
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Matías Cánepa
  • 5,770
  • 4
  • 57
  • 97
1

Facebook now supports hiding the count, use this in the markup:

data-layout="button"
Gayan Dasanayake
  • 1,933
  • 2
  • 17
  • 22
1

My solution is a little hood but it works. What I do is just basically detect where the number is going to be and use css to have a box cover over it. I guess you can also cheat the system and add more hits if you want. Here is my code using jquery but it will be different than others depending on where you place the like button on your page.

Not the most glamorous but hey the security is to tight to manipulate content in side of a frame.

<script type="text/javascript">
    var facebook_load = '';
    $(document).ready(function() {
        facebook_load = setInterval('checkIframeFacebookLoad()',100);
    });

    function checkIframeFacebookLoad() {
        if($('iframe.fb_ltr').length) {
            var parent = $('iframe.fb_ltr').parent();
            var hide_counter = $('<div></div>').attr('id', 'hide_count');
            parent.append(hide_counter);
            clearInterval(facebook_load);
        }
    }
</script>
<style type="text/css">
    #hide_count {
        position:absolute;
        top:-8px;
        left:122px;
        background:#becdd5;
        padding:5px 10px; 
    }
</style>
Rob
  • 4,927
  • 4
  • 26
  • 41
Cornelius
  • 31
  • 1
0

Adding the following to your css should hide the text element for users and keep FB Happy

.connect_widget_not_connected_text
{
    display:none !important; /*in your stylesheets to hide the counter!*/
}

-- Update

Try using a different approach.

http://www.facebook.com/share/

sakibmoon
  • 2,026
  • 3
  • 22
  • 32
RobertPitt
  • 56,863
  • 21
  • 114
  • 161
  • At least on Firefox and Chrome, it doesn't help. I tried the same CSS rule without `!important` before asking the question without success, and adding `!important` doesn't seem to change anything. See also the 3rd answer in this question: http://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe – Benjamin Wohlwend Jun 01 '10 at 13:57
  • bounty added: Are there any additional clever things you can do with the Javascript API? perhaps put your own Like button and use the API to 'like' something. i suspect that's not possible but anything else clever? – Simon_Weaver Sep 15 '10 at 02:58
  • FACEBOOK SHARE: The box_count and button_count options displays a count of the total number of times the page was shared on Facebook, how many comments were added to the story shared on Facebook, and how many times friends Liked the shared story [http://developers.facebook.com/docs/share] – Simon_Weaver Sep 15 '10 at 03:00
-1

This is what I've tried and it works fine in ff, chrome and ie8:

/* set width for the <fb:like> tag */

.fb-button {
    width:51px;
}

/* set width for the iframe below, to hide the count label*/

.fb-button iframe{
    width:45px!important;
}
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
-3

All you need to do is edit the iframe code that facebook gives you and change the width to 47 (you need to change it in 2 places). Seems to work perfectly for me so far.

Dave
  • 53
  • 1
  • 3
  • If you added more detail, this could be a good answer. There are a few different cases in hiding the count where the solution is vastly different because the problem being solved is different. – Akrikos Sep 19 '11 at 18:11