Question

I installed Disqus manually in a WordPress theme (didn't work at all via the plugin). It works fine, but I'm having trouble displaying the comment count.

I think I'm doing a lot of things right tough:

The link on the /blog/ page looks as follows:

<a href="/the-post-title/#disqus_thread" data-disqus-identifier="dq-332" title="The Post Title"><i class="fa fa-comment"></i> 0</a>

The comments.php:

<?php if (comments_open()) : ?>
<div id="disqus_thread"></div>
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'myshortname'; // Required - Replace example with your forum shortname
    var disqus_identifier = 'dq-<?php echo get_the_ID(); ?> ';

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    alert(disqus_identifier);

</script>
<noscript>Please enable JavaScript to view the comments.</noscript>

As you can see I'm alerting the disqus_identifier and therefore can verify it's being set correctly (in this case dq-332 as above)

And I am loading the count.js globally with

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'myshortname'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>

I only got it working under one (faulty) circumstance:

Before I tried it with the data-disqus-identifier it worked by appending #disqus_thread to the permalink without trailing slash, so e.g. http://mydomain.com/the-post-title#disqus_thread

The problem with that was that comments there wouldn't show up in http://mydomain.com/the-post-title/ and http://mydomain.com/the-post-title/#disqus_thread (same with the trailing slash, as generated by WordPress everywhere).

That's why I ended up with the identifier approach after all. Which doesn't have any effects so far. Would be happy about any type of hint. Cheers!

Was it helpful?

Solution

Was not able to solve it this way. Spent some more time investigating why the WordPress plugin didn't work. Worked it out in the end.

Note: you shouldn't have any relative URL plugins activated with disqus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top