Facebook comment plugin - same comments on every page

Facebook comments on my site work well, except when someone comments on one article, the same comment appears in every article on the website. Obviously, I do not want this. What I did is basically the copy and paste code offered on developers.facebook.com:

`<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_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>` `<div class="fb-comments" data-href="http://example.com" data-num-posts="2" data- width="470"></div>` 

What I did wrong? I would appreciate any help.

Vio

+4
source share
8 answers

You use the same data-href attribute for comments on the social plug-in on all pages (links to http://example.com )

You must either specify the URL of your message or leave this attribute empty (the current URL is used by default if this attribute is absent or empty) on each page there is a social plugin.

+12
source

Do not use the root URL for data-href . You must generate the URL for each page dynamically. For instance. if it was a WordPress blog, you would use the php code data-href="<?php echo(get_permalink()) ?>"

+4
source

I have the same problem, tried the solution proposed by the "juicy screenwriter", and I get "Comment plugin requires href parameter". Then I found out that a juicy solution should work if you use the version of the XFBML plugin.

In any case, the solution I implemented on my static php site was to replace href / URL with this code

  <?php echo('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?> 
+3
source

This will work fine, but I found that on one site I could not use PHP. So this worked for me as a javscript solution. Just replace the div comment with this javascript code ...

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

Try the following:

<div class = "fb-comments" expr.href = 'data: post.url' data-width = "600" data-numposts = "5" data-colorscheme = "light">

Note:

there is no space in the line above between <and div.

paste this code just above

class = 'post-footer after footer-3

Check-in: http://debaonline4u.blogspot.com

+1
source

I put the url of the page after the domain and it works for me. MyDomain is the domain from which I create the code in the comments on Facebook.

 <div class="fb-comments" data-href="http://MyDomain/Mypage URL" data-numposts="5" data-colorscheme="light"></div> 
+1
source

The problem is with data-href.

Use a dynamic URL instead.

For example, if you need a Facebook comment for each page separately.

PHP:

 data-href="<?php echo 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>" 

Hope this helps someone.

+1
source

Due to the need to separate problems .... the "data-href" tag should serve ...

For example: if you have some page www.example / 123.com ,,, your data-href value should be www.example / 123.com ....

For this, this means rendering and saving comments for www.example / 123.com, and it will not appear on other pages ....

0
source

Source: https://habr.com/ru/post/1390981/


All Articles