Hello. There is a problem. Put the social networking site facebook. I have it under every news on different pages of the site. In the settings of the wall code there is a URL , but it only goes to the main page or which one you specify.

Question: how to make the URL automatically determined for each page of the page, so as not to write it manually each time. I tried a lot of things, because in many things it is not strong.

Here is an example:

<div id="fb-root"></div> <script>(function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1 "; d.getElementsByTagName('head')[0].appendChild(js); }(document));</script> <div class="fb-comments" data-href="http://copimytest.ucoz.ru" data-num-posts="2" data-width="680"></div> 

I need to: data-href = "http://copimytest.ucoz.ru" automatically determined for each page.

Who knows, please help. Thanks in advance!

    2 answers 2

    Well, as an option, you can use javascript or jquery.

     <head> ... function onload() { document.getElementsByClassName[0].setAttribute("data-href", location.href) // $(".fb-comments").attr("data-href", location.href); } </head> <body onLoad="onload();"> ... 
    • And where it is and how to insert, you can be a bit more detailed , thanks - dilux

    <div class="fb-comments" data-href="<script>document.write(location.href);</script>" data-num-posts="2" data-width="680"></div>
    In theory, there must be a yukoz tag, but I am not strong in Yukoz.

    • not not without yukoza, it's just that I have a test site there). But unfortunately it does not come out, writes below the wall: Warning: http: // <script> document.write (location.href); </ script> is unreachable. - dilux