Tame DISQUS Comments in WordPress

DISQUS is a wonderful commenting system that increases user commets, engagement and interactivity.

Unfortunately, like most other plugins, it does some annoying things that can cause site speed issues, or in my case, minification issues.

In this post, I am assuming that you are using DISQUS comments and their respective WordPress plugin to output and manage those comments.

While in the process of redesigning and redeveloping my site, I kept running into a persistent issue of minify errors on my pages. I traced it down to minifying inline JavaScript, which was incredibly perplexing because I hadn’t inserted any inline JavaScript in my pages at the time. After some more digging, I realized that the script was coming from DISQUS and was loading on every single page of my site – yikes!


Because I’m a performance nut, I decided to figure out how I could resolve this issue because I only load comments on single blog posts. After hunting around in the admin, I couldn’t find any options or settings that would let me determine what pages the script should load. So what did I do? What any good WordPress developer would do – dig into the problem and find the source of the problem!

After hunting in the plugin, I noticed to hooks that were being used liberally without any checks: loop_end and wp_footer. Specifically, the code looked like this:

Part of me got excited because I didn’t even know the loop_end hook existed, but the other part of me shrugged because they had taken no care to check where the code should be loaded. To be fair to them, they are targeting a massive audience that may use comments on posts, pages and other post types. Even still, you could at least check and *not* output your code on archive pages. I digress.

Anyways, there was a simple solution to the problem: determine where I wanted the code to load and remove it from everywhere else. So that’s exactly what I did, and I hope you can benefit from it too.

I only load comments on single posts, so I wanted to ensure I only loaded the code on single posts. You can take this and utilize it too!

Boom. Now the unbridled JS is only loaded on our single posts. If you want to target just single posts and pages, you could use this code instead:

This code will prevent DISQUS from outputting JS on all areas of your site except for single posts and pages. We can even take this one step further to ensure that comments are actually available on the post or page before we load the code, like this:

So there you go – you can now tame DISQUS comments and make sure that they behave in a way that is performance minded.

Hope you enjoyed the tutorial! :-)

Enjoy? See Inside my WordPress Toolbox

Over 20,000 people have purchased my WordPress products. Get absolutely FREE access to regular updates and my toolbox - a collection of WordPress-related products and resources that every WordPress professional should own.

  • http://www.brandonkraft.com/ Brandon Kraft

    Very, very nice. I know what I’m dropping into the site after “real” work is finished.

    • griffinjt

      Haha thanks! I totally get what you are saying. ;-)

  • Pingback: Scion Players | Tame DISQUS Comments in WordPress()

  • Adam Penton

    Hey Griffin! Thanks for this tutorial – really helps! I am plagued by a problem on my post page. I get the error ‘DISQUS seems to be taking longer than usual. Reload?’ no matter what I do. What could be the problem. You can look for example, in this link: https://mymzone.com/blog/portobello-market-how-to-get-there/ Thanks buddy!

  • http://www.healthinformationtips.net/ health insurance

    Disqus is better for me. I’d say by far the most important reason to use disqus is that discussion on your blog will turn up on friendfeed. This gives exposure to a really influential group of people.

  • http://twitter.com/joey89924 joey

    really influential group of people.

  • http://www.healthinformationtips.net/ health insurance

    We hope Disqus update their commenting system from time to time in order to keep it working well.

  • gujjufunzone


  • http://www.expertvillagemedia.com/ WordPress Developer

    Cool and very help full in WordPress websites.

    Thanks for sharing

  • dylanized

    Dude you just saved me so much time! gracias

  • http://www.jb-webs.com/ martiin

    Wow, I installed it today in my side http://www.jb-webs.com but when I understand you article here correctly, I have to make an update by hand tommorow morning that that realy work. Is that still actual? I just ask because your articel is from July 2013, maybe there is hope that they fixed that alreay … OK, I do it on my to do list – thanks a lot to sharing this here

  • Andrea Ballerino

    Thanks Thomas for you code, works perfectly! ;)

  • brennaob

    Exactly what I was looking for. Thanks!

  • http://boirecords.co.uk/ Nick Moreton

    Thanks so much for this – I had a custom loop for a slider and this was dumping code in to one of the slides! Great fix

  • graphicbeacon

    Thank you Thomas. I recently decided to integrate Disqus into my site revamp so this will be useful.

  • thankyou
  • http://www.insurancepolicy.org.uk InsurancePolicy

    insurance policy information here

  • Kaitlin Jurasek

    Hi, Thanks for the info. Where exactly am I supposed to put this code? I am having issues trying to get Disqus to post separately on each of my blog posts! It just keeps posting them in a long stream from the previous comments. HOW DO I FIX THIS!?!?

  • http://www.realisingdesigns.com James Montgomery

    This is great, tidies the code up nicely, thanks.

  • Zoraakh

    Great Article , i am blogging since 2 years and applied for adsense account and it was approved but since than i am earning daily just 1 to 2 $ but after reading this article i will must focus on http://www.lashwallpapers.com what mistakes i am doing.. and hope that i will increase my earning .. i heard of this blog from http://www.dailybix.com . thanks for such great post.. http://www.paktvfun.com i love disqus

  • http://reessay.com/essay-writing.html Cheap Essay

    Thanks for shearing.


  • Guest


  • Mark Thomson

    Hi, I need help with this and was relieved to find your post. However your code is not showing up. Perhaps a templating issue?

    I’m looking forward to see your solution as I’ve been racking my brain with this problem for a while.


    • https://thomasgriffin.io/ Thomas Griffin

      Hey Mark – it should show now. Can you confirm for me? You may need to refresh the page.

      • Mark Thomson

        It’s showing now, thanks. I’m quite new to wordpress and the solution I came up with was to call add_action( ‘wp_footer’, ‘remove_disqus’,19); Which then dequeued the count.js.

        Problem was, Disqus doesn’t enqueue the script until the wp_footer hook which meant finding the correct priority number was a chore.

        Anyhow, I didn’t know remove_action() even existed. It’s a much more elegant solution. Thanks for the quality post.

        Side note: I couldn’t find a hook into loop_end in the latest disqus plugin. Either it’s been removed or I’m blind :-)

        Cheers Thomas

        • https://thomasgriffin.io/ Thomas Griffin

          I’ll need to check the latest version to see if the code still applies – but I know it did pre-2.8. :-)