Daniel J. Lewis

Internet entrepreneur, award-winning podcaster, podcast consultant, keynote speaker

  • RSS
  • Periscope
  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Snapchat
  • Instagram

Powered by Genesis

How to disable Disqus on WordPress custom post types

July 28, 2013 by Daniel J. Lewis 68 Comments

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.

// Remove Disqus from a custom post type
remove_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
add_action( 'the_post' , 'block_disqus');
function block_disqus() {
    if ( get_post_type() == 'custom_post_type_name' )
        remove_filter('comments_template', 'dsq_comments_template');
}

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.
        $replace = get_option('disqus_replace');
    
        if ( is_feed() ) { return false; }
        if ( !isset($post) ) { return false; }
        if ( 'draft' == $post->post_status ) { return false; }
        if ( !get_option('disqus_forum_url') ) { return false; }
        else if ( 'all' == $replace ) { return true; }
  3. Add the following above the if statements. (Replace “product” with your post type, or duplicate this line to address several post types.)
        if ( 'product' == get_post_type() )    { return false; }

    So that your code looks like the following.

        $replace = get_option('disqus_replace');
    
        if ( 'product' == get_post_type() )    { return false; }  
        if ( is_feed() )                       { return false; }
        if ( 'draft' == $post->post_status )   { return false; }
        if ( !get_option('disqus_forum_url') ) { return false; }
        else if ( 'all' == $replace )          { return true; }
  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!

Filed Under: Technology, Web design Tagged With: custom post types, Disqus, PHP, plugins, WooCommerce, WordPress

Get posts like this automatically emailed to you!

Click here to subscribe

Comments

  1. RichTheRookie says

    August 23, 2013 at 2:27 am

    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! 🙂

    Reply
    • Daniel J. Lewis says

      August 23, 2013 at 7:31 am

      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.

      Reply
  2. Ruby says

    September 5, 2013 at 5:48 am

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

    Reply
  3. David says

    September 20, 2013 at 11:57 am

    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!

    Reply
    • Daniel J. Lewis says

      September 20, 2013 at 12:44 pm

      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!

      Reply
  4. Paolo Albera says

    September 25, 2013 at 10:16 am

    Really simple and effective fix!
    Works like a charm!

    Thanks!

    Reply
  5. Stu says

    September 30, 2013 at 8:24 pm

    Awesome! Thanks

    Reply
  6. test name says

    October 3, 2013 at 6:05 am

    Thanks…

    Reply
  7. Strobius Ru says

    October 3, 2013 at 11:08 am

    Thank you very much!

    Reply
  8. Qasim says

    October 13, 2013 at 12:42 pm

    Thank you so much!

    Reply
  9. Byron says

    October 22, 2013 at 7:22 pm

    Thanks, worked perfectly!

    Reply
  10. Giuseppe Lanzetta says

    November 4, 2013 at 11:21 am

    Thanks, so helpful!

    Reply
  11. Onur Güven says

    November 9, 2013 at 2:18 pm

    Thanks, but 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;

    }

    Reply
    • Daniel J. Lewis says

      November 9, 2013 at 2:40 pm

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

      Reply
    • Randy Garmon says

      February 21, 2014 at 1:45 pm

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

      Reply
    • Timothy Johnson, VA says

      October 30, 2014 at 9:26 am

      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

      Reply
    • Daniel J. Lewis says

      November 19, 2014 at 12:06 pm

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

      I updated my post. Thanks!

      Reply
      • Onur Güven says

        November 20, 2014 at 2:08 am

        you’re welcome 🙂

        Reply
        • Guest says

          November 20, 2014 at 2:17 am

          …

          Reply
  12. Israel Castro says

    January 28, 2014 at 2:48 pm

    Thanks! That resolved my problem with the reviews on woocommerce

    Reply
  13. Randy Garmon says

    February 21, 2014 at 1:43 pm

    Worked like a charm!

    Reply
  14. Dutchie says

    April 1, 2014 at 5:24 pm

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

    Reply
  15. legalzebra says

    April 10, 2014 at 1:14 am

    awesome, thanks, worked a treat. much appreciated.

    Reply
  16. Piers says

    May 22, 2014 at 6:44 am

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

    Reply
  17. Mora says

    August 13, 2014 at 7:46 pm

    Thanks so much!!!

    Reply
  18. Eva says

    September 14, 2014 at 8:22 am

    Ah finally, thank you!

    Reply
  19. GroundSmart says

    September 25, 2014 at 1:12 pm

    This worked perfectly, thanks!

    Reply
  20. Timothy Johnson, VA says

    October 30, 2014 at 9:24 am

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

    Reply
  21. Monika Czaplicka says

    January 19, 2015 at 9:19 pm

    THANK YOU <3

    Reply
  22. tgrapher_master says

    March 2, 2015 at 11:19 pm

    // 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;

    }

    Reply
    • Daniel J. Lewis says

      March 5, 2015 at 4:58 pm

      Yes, that’s what I already have.

      Reply
  23. Arthur Rosa says

    March 12, 2015 at 7:02 pm

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

    Reply
    • Daniel J. Lewis says

      March 12, 2015 at 7:04 pm

      Great! 🙂

      Reply
  24. WooGang says

    April 6, 2015 at 2:04 pm

    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

    https://gplchimp.com/best-woocommerce-shortcodes-extensions/

    Reply
    • Daniel J. Lewis says

      April 10, 2015 at 10:41 pm

      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.

      Reply
  25. N3gATiVE says

    April 18, 2015 at 9:25 am

    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.

    Reply
    • Daniel J. Lewis says

      April 19, 2015 at 6:44 pm

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

      Reply
      • N3gATiVE says

        April 25, 2015 at 5:05 pm

        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!

        Reply
        • Daniel J. Lewis says

          April 28, 2015 at 3:50 pm

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

          Reply
          • Mahdieh says

            May 12, 2015 at 6:34 pm

            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.

          • Daniel J. Lewis says

            July 21, 2015 at 5:40 pm

            I figured this out. Please update to the code in my example.

        • Mahdieh says

          May 12, 2015 at 6:37 pm

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

          Reply
    • Daniel J. Lewis says

      July 21, 2015 at 5:40 pm

      I’m sorry it took me so long, but I did figure this out and it’s working now. Please update your code to my new example.

      Reply
  26. brain says

    May 12, 2015 at 1:14 am

    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?

    Reply
  27. brain says

    May 12, 2015 at 6:22 am

    thank your coding !~~ it really worked

    Reply
  28. Discount Card says

    May 16, 2015 at 8:54 pm

    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.

    Reply
  29. Product says

    May 16, 2015 at 9:01 pm

    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.

    Reply
  30. Paul Alan Clifford says

    June 4, 2015 at 4:40 pm

    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.

    Reply
  31. Kelplat says

    July 13, 2015 at 5:02 pm

    Thanks a lot. It works perfectly on kelplat.com/kelchef.

    Reply
  32. Jonny says

    July 29, 2015 at 3:46 am

    Helped us out massively at https://www.woosociety.com. Thank you!

    Reply
    • Daniel J. Lewis says

      July 29, 2015 at 7:43 am

      Great!

      Reply
  33. Andy says

    September 8, 2015 at 1:18 pm

    Absolute legend. Thank you for this.

    Reply
  34. Robin Neal says

    November 26, 2015 at 8:40 am

    Hi, I’ve just been adding this to a site I’m currently building which uses WooCommerce and Disqus comments. I found the get_post_type() statement to be causing issues, where certain widgets were not correctly resetting the post type.
    I’ve found a more reliable technique is to use is_singular(‘POST_TYPE’). This ensures the disqus comments are only disabled when on a singular page for the specified post type.

    Reply
    • Daniel J. Lewis says

      December 1, 2015 at 2:54 pm

      Can you explain more or link to an example where the conflict was happening?

      Reply
      • Robin Neal says

        December 2, 2015 at 10:55 am

        Sorry, it’s been a little while since I was working on that so this may be a bit vague.

        In my case I wanted to only use disqus on the posts section, removing it from products. However, the_post is called on any WP_Query loop on the page. This meant that the loop in my header for the mini-basket, and the loop in the sidebars for recent products (or whatever) would also call the_post, and return true for the get_post_type(), despite the page being a singular post. This meant disqus was being removed from all pages, because there was always a post with the type of product somewhere on a page.
        is_singular(), on the other had, will only return true if it is a single post of the specified post type, thus is much more reliable. It would possibly make even more sense use a unique action, such as init or wp_head, so that you can avoid it being called twice.

        I hope this makes sense, if you want a further explanation I’ll send you an email.

        Reply
  35. Marc says

    April 20, 2016 at 3:17 pm

    Thanks for this. Works fine for me.

    Reply
  36. Rinat says

    April 27, 2016 at 8:38 am

    GOD BLESS YOU DANIEL!!!!!! I’ve spent 2 hours of searching the solution! And your method has worked!!! Thank you so much!

    Reply
  37. Pascal Winnen says

    May 11, 2016 at 6:12 pm

    Very nice! Thanks!!

    Reply
  38. VeloNomad says

    May 13, 2016 at 9:58 pm

    Can you paste a raw snippet of the code please?

    Reply
    • Daniel J. Lewis says

      May 13, 2016 at 11:46 pm

      Hover your mouse over the code and you’ll have the option to view or copy the raw code.

      Reply
  39. zamartz says

    June 1, 2016 at 1:17 am

    Wow looking into this spiraled out of control. So I ended up making an extension for Woo Commerce to make it easier https://zamartz.com/2016/06/01/woocommerce-disqus-comments-and-ratings/

    Reply
  40. zamartz says

    November 6, 2017 at 7:54 pm

    I also created a solution here https://wordpress.org/plugins/woo-dis-comments-and-ratings/

    Reply
  41. Peter Manoukian says

    November 7, 2017 at 4:59 am

    How can I disable displaying the comments of draft posts on wordpress on the disqus display
    Regards

    Reply
    • Daniel J. Lewis says

      November 7, 2017 at 9:52 am

      Please contact Disqus support for help with that.

      Reply
  42. Andy Globe says

    January 27, 2022 at 8:38 am

    Ok, i see… In case i disable Disqus in custom post type, what happens then? Does that post stay with comments disabled? Or in that case, WP Comments are back to the page?

    Reply
    • Daniel J. Lewis says

      February 14, 2022 at 11:03 pm

      It’s been a long time since I used Disqus on an active site. But I believe that following these steps would disable only Disqus but leave the comments according to your WordPress settings.

      I had to do this in order to fix reviews that weren’t showing on a product because Disqus was taking over.

      Reply

Trackbacks

  1. Why use self-hosted WordPress for podcasting? says:
    August 19, 2013 at 5:10 pm

    […] example, I was able to easily find others who wanted to disable Disqus on certain WordPress post types. But in my case, no one else had the solution, so I discovered it for […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Home
  • About me