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).
- Open up the “disqus.php” file in the Disqus plugin folder (usually “/wp-content/plugins/disqus-comment-system/disqus.php”).
- Find line
149143 (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; }
- 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; }
- Save and re-upload the “disqus.php” file.
- 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!