How to disable Disqus on WordPress custom post types

UPDATE: Disqus is pushing out more updates, which would mean re-implementing this code each time. Thus, I changed methods. Thanks to Onur Güven (in the comments) for pointing out the better method.

If you have custom post types on your WordPress website and use Disqus Commenting System, you may have a need to disable Disqus in only certainly places. I’ll show you how!

I created a premium WordPress plugin, Social Subscribe & Follow Icons, for adding vector social icons to blog and podcast websites. Since I podcast “how-tos” about podcasting to other podcasters (I’m a meta kind of guy), I sell this plugin on The Audacity to Podcast’s website. My site uses Disqus and I sell the digital product with WooCommerce.

WooCommerce (and other ecommerce plugins for WordPress) creates custom post types and may use the default WordPress comments system for managing reviews on those products. The problem is that Disqus takes over the commenting system and now disables the WordPress system. This results in a blank Reviews tab for my products on my website.

To fix the problem, we need to tell Disqus not to run on a particular post type, and let the default WordPress system take over. In the case of WooCommerce, this custom post type is “product,” but it could be any other post type in your case.

Open your theme’s functions.php file and add the following code near the bottom.

Where  custom_post_type_name is the name of your post type, like  product.

Now, you can update Disqus without losing your settings! Just remember to re-implement this code if you update or switch themes.

Old method (no longer recommended)

The following instructions are for Disqus version 2.74 through 2.77 2.79. Later version will probably work the same (though line numbers may change, as they did for version 2.79).

  1. Open up the “disqus.php” file in the Disqus plugin folder (usually “/wp-content/plugins/disqus-comment-system/disqus.php”).
  2. Find line 149 143 (as of version 2.79) and you’ll see the following.
  3. Add the following above the  if statements. (Replace “product” with your post type, or duplicate this line to address several post types.)

    So that your code looks like the following.
  4. Save and re-upload the “disqus.php” file.
  5. You may need to clear your cache.

Following these steps, Disqus will be disabled on these custom post types. In my scenario, this means I can now accept product reviews in my WooCommerce store!

I’ve shared this post with Disqus so that they can consider including this code in the future, or building in a function to allow users to select post types.

If this was helpful, please reshare it!

Get posts like this automatically emailed to you!

  • Pingback: Why use self-hosted WordPress for podcasting?()

  • RichTheRookie

    You sir, are a life-saver! I’ve been searching all over for a way to fix this problem with Disqus.

    I tried what you did but found that this worked instead:

    Instead of “if ( ‘product’ == get_post_type() ) { return false; }”

    It should be: “if ( ‘product’ == $post->post_status ) { return false; }” with product being replaced with whatever your custom post is named.

    You see, I installed EditFlow which creates a couple of custom post-types, and as my writers would preview an article that wasn’t saved as a “Draft”, Disqus would activate, thus creating comment conflicts resulting in comments publishing on the wrong post.

    Thanks a million for pointing me in the right direction though. Much appreciated! :)

    • http://DanielJLewis.net/about Daniel J. Lewis

      Great!

      So you had a different goal than I did? Because your suggested code doesn’t work on the product post type from WooCommerce.

      However, maybe both your line and mine should be added.

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

    Great !!!!!!! really very helpful article in WordPress projects.

  • David

    Awesome find – thank you! Just to add to the comments – if I may (to help future stragglers like me):

    It seems as if you can employ most of WordPress’ native functions to test against. I had a specific category to exclude Disqus on so:

    if (is_category( ’14’ ) ) { return false; }

    also worked

    Thank you!

    • http://DanielJLewis.net/about Daniel J. Lewis

      Exactly! Once you know where to put the line and what code to use, you can adjust it to your needs.

      Thanks for stopping by and commenting!

  • http://www.paoloalbera.com/ Paolo Albera

    Really simple and effective fix!
    Works like a charm!

    Thanks!

  • Stu

    Awesome! Thanks

  • test name

    Thanks…

  • http://strobius.ru/ Strobius Ru

    Thank you very much!

  • Qasim

    Thank you so much!

  • http://www.oldgoatcycleworks.com/ Byron

    Thanks, worked perfectly!

  • http://www.giuseppelanzetta.com/ Giuseppe Lanzetta

    Thanks, so helpful!

  • Onur Güven

    is not the correct method.
    add the following code to your functions.php file inside your theme.

    add_filter( ‘comments_template’ , ‘block_disqus’, 1 );
    function block_disqus($file) {
    if ( ‘custom_post_type_name’ == get_post_type() )
    remove_filter(‘comments_template’, ‘dsq_comments_template’);
    return $file;

    }

    • http://DanielJLewis.net/about Daniel J. Lewis

      Thanks, Onur! I’ll give this a try as this could be better than modifying the plugin source.

    • http://www.slamcreative.com/ Randy Garmon

      If the net result is the same, why does it matter?

    • Timothy Johnson, VA

      This is definitely a better option than modifying the Disqus plugin. I also use the Disqus Conditional Load plugin instead of the main one, and the process is relatively the same

    • http://DanielJLewis.net/about Daniel J. Lewis

      I did finally test this, and it works just as well, but without being susceptible to plugin updates.

      I updated my post. Thanks!

      • Onur Güven

        you’re welcome :)

        • Onur Güven

  • http://iscasur.com/ Israel Castro

    Thanks! That resolved my problem with the reviews on woocommerce

  • http://www.slamcreative.com/ Randy Garmon

    Worked like a charm!

  • Dutchie

    Excellent, added the filter in functions and works like a charm. Many thanks!

  • http://www.legalzebra.com.au/ legalzebra

    awesome, thanks, worked a treat. much appreciated.

  • Piers

    Worked perfectly thanks! Saved me a lot of time trying to find a solution

  • http://kboost.net/ Mora

    Thanks so much!!!

  • http://lapinnoir.nl/ Eva

    Ah finally, thank you!

  • GroundSmart

    This worked perfectly, thanks!

  • Timothy Johnson, VA

    This did work well, I wish there was a non-hacky way to do this though.

  • http://czaplicka.eu/ Monika Czaplicka

    THANK YOU <3

  • tgrapher_master

    // Remove Disqus from a custom post type

    add_filter( ‘comments_template’ , ‘block_disqus’, 1 );

    function block_disqus($file) {

    if ( ‘product’ == get_post_type() )

    remove_filter(‘comments_template’, ‘dsq_comments_template’);

    return $file;

    }

    • http://DanielJLewis.net/about Daniel J. Lewis

      Yes, that’s what I already have.

  • https://arthurrosa.com/ Arthur Rosa

    Thank you, Daniel! You really helped me without even know me. 😛

    • http://DanielJLewis.net/about Daniel J. Lewis

      Great! :)

  • http://woogang.com/ WooGang

    We just tried disqus with woocomemrce using your code and we were successful but we are facing another problem, It keeps on saying comments are closed on blog post even though it is open. Any idea

    http://woogang.com/best-woocommerce-shortcodes-extensions/

    • http://DanielJLewis.net/about Daniel J. Lewis

      You might need Disqus’s help on that one. You may have a setting in Disqus that closed all of your blog posts, or maybe just your old ones.

  • N3gATiVE

    Code is worked but still can’t write reviews as we will click submit button it will throw error:

    Sorry, the built-in commenting system is disabled because Disqus is active.

    • http://DanielJLewis.net/about Daniel J. Lewis

      You may need to get help from whatever ecommerce software you’re using.

      • N3gATiVE

        Using WordPress Woocommerce recent version, after applying your code Woocommerce reviews is stated showing then as we write some review and click “Submit” Review button it throws error:

        Sorry, the built-in commenting system is disabled because Disqus is active.

        Screen: http://oi59.tinypic.com/a3mdew.jpg

        Any idea or help on solving this tried to search alot but not getting any fix! and have you also notice this problem in your WooCommerce store reviews or its only me!

        • http://DanielJLewis.net/about Daniel J. Lewis

          I don’t think I’ve had that same problem. You might need to talk to WooCommerce about that one.

          • http://dndinc.org Mahdieh

            Hi Daniel,
            thank your coding.it was usefuel for me .

            when i installed disqus .it took over tab product reviews after adding these codes it works well but i want also to have disqus commenting for product reviews .
            have a good days.

        • http://dndinc.org Mahdieh

          i had same problem .i added all two method that Daniel said.

  • brain

    i using the code. it didn’t anything worked.
    my woocommerce still can’t not read reviews.

    “custom_post_type_name” i change “tab-reviews”
    what mistake did i make?

  • brain

    thank your coding !~~ it really worked

  • http://www.crownhealthcarerx.com/ Discount Card

    On November 9, 2011, the Federal Emergency Management Agency (FEMA) conducted the first nationwide test of the Emergency Alert System (EAS). The test was conducted at 2:00pm EST and during this period, regularly scheduled television, radio, cable, radio and satellite shows were interrupted as the system was being tested.

  • http://www.smsmaster.com.au/product Product

    On November 9, 2011, the Federal Emergency Management Agency (FEMA) conducted the first nationwide test of the Emergency Alert System (EAS). The test was conducted at 2:00pm EST and during this period, regularly scheduled television, radio, cable, radio and satellite shows were interrupted as the system was being tested.

  • http://trinitydigitalmedia.com/ Paul Alan Clifford

    Hope the move to AZ is going well (I’m partial to Flagstaff myself, having spend a summer at the Grand Canyon).

    Anyway, thanks for the code. Seems to have worked like a charm. Now, if I can just figure out how to import all my Amazon reviews without just copying and pasting, all will be well.