Have you ever wanted to disable displaying Disqus plugin on certain custom post types? well if yes, then follow us to teach you how you can disable disqus comment section on predefined post types.
Disqus a really good comment plugin for wordpress that has a lot of good features, it’s very easy to install, and it displays the comment form automatically. but in most cases users don’t want the disqus to display, example of such cases are :
- Shop section of the blog (you want to show normal comment form as review section)
- Have different comment form for some post types
- Display Disqus on blog articles but display normal comment form in Pages
if you are having a similar problem, here is how to solve it:
First you need to know on which post types you want to disable displaying disqus, below are some examples:
- post
- page
- product
- attachment
- review
- any other post type
Second, after you know the post type, all you have to do is insert this code inside your Functions.php file in your theme folder :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //how to disable disqus on custom post types function wppremium_disable_discus($file) { $exclude_disqus=array('product');// you can add more post types here $current_post_type=get_post_type(); if ( in_array($current_post_type,$exclude_disqus) ) remove_filter('comments_template', 'dsq_comments_template'); return $file; } add_filter( 'comments_template' , 'wppremium_disable_discus', 1 ); |
as you see in the above code, you can add more post types if you want, in the code above, we removed disqus from “product” post type, after this disqus won’t display for product post types, just add any number of post types in this line, for example :
1 | $exclude_disqus=array('product','page','review'); //disable disqus on "product","page","review" post types |
We hope this article was helpful for you to disable Disqus on certain custom post types in WordPress.
please share your experience with this issue in the comments section below.