Facebook Like button likes whole page instead of post (wordpress)

I’m working on this page and I use WordPress as my CMS.

On the index.php page where all my posts show up I want to add a Facebook Like button underneath the title to instantly like a post without going to “Read More”.

Read More

But when I click “Like” it likes all of my blogposts so all of them get +1. Is there any way to make the code ONLY like the content of that post the button is clicked?

I’m using the following code:

<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=266693680020880";
                    fjs.parentNode.insertBefore(js, fjs);
                  }(document, 'script', 'facebook-jssdk'));</script>
                <div class="fb-like" data-send="true" data-layout="button_count" data-width="100" data-show-faces="false"></div>

Related posts

Leave a Reply

3 comments

  1. You need to specify data-href="http://<<your blog url>>" to like blog instead of page.

    For e.g.

    <div class="fb-like" data-send="true" data-href="http://<<your blog url>>" data-layout="button_count" data-width="100" data-show-faces="false"></div>
    
  2. Such like buttons are just refering to an URL.

    If you want the buttons to have individual “likes”, then you’ll need to provide an unique URL for each one of them. (The URL of the post they are refering to.)

    You set the URL with the data-href attribute on the <div class="fb-like" data-href="URL"....> element.

    Note that http://example.com and https://example.com is TWO individual sites when it comes to like buttons.

  3. These are close but in wordpress you’ll want to call

    <div class="fb-like" data-send="true" data-href="<?php the_permalink()?>" data-layout="button_count" data-width="100" data-show-faces="false"></div>
    

    in your loop. That should set up the post to be likes.