Multiple Facebook Like or Share Buttons on One Page

Nowadays, the Facebook’s Like and Share buttons have become very important tool for sharing articles on the world’s largest social network. Therefore, a large number of websites deploy this tiny button so as to allow users to share content easily.

Often, people want to put more than one Like and Share buttons on the same web page. For example, one to like the domain name of the website (e.g. www.example.com) and another to like the particular article (e.g. www.example.com/my-article). Moreover, sometime you might want to show a like button opposite every item in a list of articles! Let’s see how it is done.

Use Only One Div with ID “fb-root”

Many people simply copy the code provided by Facebook and paste it in their webpage. For the next button they will create another instance of the code from Facebook and paste it again in their web page. This creates multiple instances on fb-root div in your code. To avoid this place the following code right before opening the body tag:

<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/sdk.js#xfbml=1&appId=287600731342777&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
Add Multiple Like or Share Buttons

When you add a Facebook Like button on a webpage, you need to understand that every such button likes a unique URL. That is to say that every FB Like button must be associated with a unique URL.

Use the following code to add as many Like buttons as you want. Just keep pasting this code wherever you need the Like button:

<div class=”fb-like” data-href=”UNIQUE-URL” data-layout=”standard” data-action=”like” data-show-faces=”true” data-share=”true”></div>

You can have multiple buttons if you repeat the above DIV tag.

Just don’t forget to change the data-href value as required.

If you’ll paste this DIV multiple times but will not change the data-href value, you will still see multiple FB Like buttons but they all will show same number of likes because they all will be associated with one URL.

If you follow these steps and change data-href value appropriately, all your Like buttons should be working fine now!

This is how multiple buttons are placed on a webpage. It works for most people but if it is not working for you, you need to investigate the issue as there could be something wrong elsewhere in your website.

9 thoughts on “Multiple Facebook Like or Share Buttons on One Page”

  1. Hi,

    Let’s say I have a page with a list of products. I want to be able to share(on Facebook) the whole list (a link to the list) and also I want to be able to share a single product from this list w/o going to the products page(!).

    The list share obviously is simple enough, but what about when I want the meta tags to change dynamically for the product I want shared?

    So far I tried with an ajax call to the product page, set some tags from there and have it change on the Master page if the url contains the a product page.

    This doesn’t work all the time and it’s ‘hacky’. I found a good article on how to easily implement meta-tags in ubmraco and have it change dynamically based on the page you are, but seeing as the product is on the same page as the list it doesn’t work.

    How can I implement this? I’ve been having a lot of trouble with this lately.

  2. Hi, i dont know if it relates to your discussion as i’m not a technical guy. But would like to ask if its possible to have different small posts on one page with separate sharing button for each of them without creating new pages for each?

  3. This works for share button, but I still pull multiple requests of the same assets from their server at 7kb each
    Any idea how to reuse the same one? Same with twitter share button.

    1. I understand the problem and I agree with you. If we could reuse the assets, using multiple share buttons could have become much faster. But unfortunately, so far such an option has not been provided by the social media platforms.

    1. Well for multiple wp posts you add this in the loop, <div class="fb-share-button" data-href="” data-layout=”button_count”> and each share can use it’s own permalink

  4. Thanks for this. I have implemented just as specified. It seems to be working fine in FF. However, in IE8, I am getting the following:

    Message: Unknown runtime error
    Line: 144
    Char: 688
    Code: 0
    Message: Object doesn’t support this property or method
    Line: 137
    Char: 406
    Code: 0

    Any ideas?

Leave a Comment

Your email address will not be published. Required fields are marked *