Search code examples
facebookwordpressfacebook-commentsfacebook-social-plugins

Want the facebook comment box url dynamically assigned according to posts


I am working to create a website using wordpress. There are a number of posts in my web site. I am to add the facebook comment button that appears below every single posts in my site. For this purpose I used the facebook social plugin.

I added the codes generated at facebook developers site to my single post page file. Now the problem is: The same comments appear in every page in my posts everywhere. how can I make this a specific one .

<div class="fb-comments" data-href="http://rabindraadhikari.com" data-width="600" data-numposts="3" data-colorscheme="light"></div>

I want to change the data-href part of the code so that it assigns the url according to the page where it is displayed. The format of the posts url belonging my site is www.domain-name.com/post-id How can it be done??

Somewhere, I found it can be done like this but it didnt work

<div class="fb-comments" data-href="+location.href+" data-num-posts="3" data-width="470"></div>

Solution

  • location.href is a property from javascript, so

    <script>
    document.write('<div class="fb-comments" data-href="'+location.href+'" data-num-posts="3" data-width="470"></div>');
    </script>