Tuesday, 19 June 2012

Blogspot and Disqus

Blogspot and Disqus have an incompatibility:

  • Blogger uses per-country domains like refusingthedefault.blogspot.co.uk for the UK, and refusingthedefault.blogspot.com for the US (and anywhere not specifically stated). A few other countries are similarly affected.
  • Disqus ties its comment threads to a particular URL. So while you can allow multiple domains to connect to the Disqus account in Settings => Trusted Domains, that ends up with you having a separate unrelated comment thread for every country. Not great if you have any international readers.

For now, people can go to refusingthedefault.blogspot.com/ncr to make the domain stick with country geo-location. This is not great, but it kind-of works at great inconvenience to your readers...

I've found a better fix, which does not appear to be documented elsewhere on the web (and Disqus support didn't mention it when I asked), but it's so obvious from a programming perspective I find it unlikely I'm the first to think of it. On the other hand, it does require a little bit of willingness to dive into the raw template code to implement, so make sure you backup your template first in case it goes wrong.

Code for the fix below the cut...

In the Blogger template with Disqus installed there'll be a section like:

<script type='text/javascript'>
                var disqus_url = '<data:post.url/>';;
                var disqus_title = document.getElementById('disqus_post_title').innerHTML;
                var disqus_message = document.getElementById('disqus_post_message').innerHTML;

(Edit the template, edit the HTML directly, disregard the "are you sure" warning, and expand the widget templates)

After the line starting 'var disqus_url' add:

disqus_url = disqus_url.replace(/refusingthedefault.blogspot.[a-z.]+/,"refusingthedefault.blogspot.com");

(replacing "refusingthedefault" with your blogspot domain, or it won't do anything useful...)

This will pass the canonical post URL to Disqus, and your comments will be unified. There will probably be a bit of a mess with old comment threads that needs migrating on Disqus.

Add the blogspot country subdomains to your Trusted Domains in Disqus and it should all work (except for the comment counts on the summary page, which will always say zero, but that's bearable)