-
-
Save nternetinspired/7482445 to your computer and use it in GitHub Desktop.
// Requires jQuery of course. | |
$(document).ready(function() { | |
$('.show-comments').on('click', function(){ | |
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username. | |
// ajax request to load the disqus javascript | |
$.ajax({ | |
type: "GET", | |
url: "http://" + disqus_shortname + ".disqus.com/embed.js", | |
dataType: "script", | |
cache: true | |
}); | |
// hide the button once comments load | |
$(this).fadeOut(); | |
}); | |
}); |
<!-- An element a visitor can click if they <3 comments! --> | |
<button class="show-comments">Load Disqus comments</button> | |
<!-- The empty element required for Disqus to loads comments into --> | |
<div id="disqus_thread"></div> |
It's more practical to use protocol-relative URL, '//' instead of 'http://'. Disqus also suggests it in their template code.
How does this work on WordPress blog posts?
@seb86 you could just place the HTML code into the single.php file and the SCRIPT into the footer.php and that should do it.
@rrecinos Do I not have to specify a post ID?
Possible to make that button toggle comments on and off?
Thank you very much 👍
Piggybacking off of euler0's comment, in this day and age you really just want to use HTTPS instead of protocol-relative.
See for example https://jeremywagner.me/blog/stop-using-the-protocol-relative-url
Why does it has to be jquery? Can't JavaScript do this? Since it's to reduce bloat might as well do it in pure JavaScript.
How to specifiy postID etc... ?
Fixed: I fixed the problem. The problem was that blogger redirects to the country specific blogger domain. That's when disqus looses the thread-url. I needed to use the disqus variables from their original code (https://help.disqus.com/customer/portal/articles/888340-manually-adding-a-disqus-gadget-to-blogger). The second problem was the embed.js script. I changed it to blogger_item.js and now everything works fine.
(original question)
When I use this code for my blog, commens which already have been postet to it are not displayed. Somehow Disqus can not make the reference to the previous comments. Is there a way to fix this? Can I use the page URL as parameter somehow? I created a test-blog and there it works. Only difference: my shortname. the shortname for my real blog has "-" in it. Can it effect it? Do I need to escape them?