Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link facebook comments widget to the current url?

I've got a bit of a problem with facebook comments box on my website. I can't figue out a way for it to link the comments to the url they are on. For example a fb comment to Post 1 on my site is shared between all of my post wich can be a bit misleading for the users. I post about hundred posts a day (pics mainly), there's no way I can make a new box for each and every one of them.

Here's the piece of code that's troubling me:

<div class="fb-comments" data-href="funshit.ru" data-num-posts="5" data-width="530" data-colorscheme="dark"></div>

If only there was a way to make it link to the current url the problem'd be solved.

Any help is appreciated m8s.

like image 836
user1127954 Avatar asked Jan 17 '23 21:01

user1127954


1 Answers

Because the CMS I was coding in didn't reliably return the current URL and leaving it blank or omitting it failed, I wrote the div tag in Javascript:

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

Of course, this will include the data in the query string but you should be able to exclude that if that's what you want.

like image 145
Rimian Avatar answered Feb 05 '23 17:02

Rimian