How to Disable Disqus Comments Option on Custom Post Type in WordPress

If you have been running/managing a website, you’d probably be familiar with Disqus Comment system. Since it inception, it has garnered a lot of popularity among web users. Today, Disqus powers more than 75% of the websites worldwide. And the figure is quickly growing every year.

Disable Disqus Comments Option on Custom Post Type in WordPress

Popular features of Disqus Commenting System:

  • It comes directly integrated with various popular services such as Squarespace, Tumblr, and WordPress
  • Offers Engage, an added functionality, that provides tools and comments for monitoring and managing your commenters
  • Comes with a powerful moderation dashboard with commenters reputation, word filters, spam controls, ban lists and more
  • Integrated with an inbuilt analytics tool to help you understand your audience.

However, recently we have been asked by many of our readers how they can disable Disqus comments option on their custom post type in a WordPress website. So, instead of replying each one of them separately, we decided to write this post and help our readers perform the task-at-hand.

Well, a custom post type in a WordPress is created to add your own particular type of content such as posts and pages with additional features. You can easily create a custom post type using register_post_type() function. It enables you to represent a new post type via its availability, supported features, labels, and other specifications.

If you use a custom post type in your WordPress website and need to disable the Disqus comments option, read on.

We are going to discuss three different methods of disabling the comments option on your WordPress website. So, you can use any method as per your technical skills and knowledge.

Note: Before making any changes in your website files, make sure you have a complete backup of your websites only to ensure that you can always get back up if something goes wrong.

Method 1: Making changes in the functions.php files or site-specific plugin

Well, this is one of the simplest ways to disable Disqus Comments option. All you have to do is to copy and paste the following code snippet in your functions.php or site-specific plugin file.

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

function wpb_block_disqus($file) {

if ( ‘custom_post_type_name’ == get_post_type() )

remove_filter(‘comments_template’, ‘dsq_comments_template’);

return $file;

}

Replace the custom_post_type with your website’s custom post type name and save your file.

What this code does is puts a filter to track a particular custom post type and disable Disqus comment template display.

Method 2: Disable during initialization of custom post type

You can always customize the setting of custom post type at the time of its initialization. Define the list of supported functionalities with “supports” argument before calling register_post_type().

Here is an example of a custom post type of shoes:

add_action( ‘after_setup_theme’, ‘woocommerce_support’ );

function woocommerce_support() {

add_theme_support( ‘woocommerce’ );

}

add_action( ‘init’, ‘custom_type_shoes_init’ );

//Register a shoes post type.

function custom_type_shoes_init() {

$labels = array(

‘name’               => _x( ‘shoess’, ‘post type general name’, ‘your-plugin-textdomain’ ),

‘singular_name’      => _x( ‘shoes’, ‘post type singular name’, ‘your-plugin-textdomain’ ),

‘menu_name’          => _x( ‘shoes’, ‘admin menu’, ‘your-plugin-textdomain’ ),

‘name_admin_bar’     => _x( ‘shoes’, ‘add new on admin bar’, ‘your-plugin-textdomain’ ),

‘add_new’            => _x( ‘Add New’, ‘shoes’, ‘your-plugin-textdomain’ ),

‘add_new_item’       => __( ‘Add New shoes’, ‘your-plugin-textdomain’ ),

‘new_item’           => __( ‘New shoes’, ‘your-plugin-textdomain’ ),

‘edit_item’          => __( ‘Edit shoes’, ‘your-plugin-textdomain’ ),

‘view_item’          => __( ‘View shoes’, ‘your-plugin-textdomain’ ),

‘all_items’          => __( ‘All shoes’, ‘your-plugin-textdomain’ ),

‘search_items’       => __( ‘Search shoes’, ‘your-plugin-textdomain’ ),

‘parent_item_colon’  => __( ‘Parent shoes:’, ‘your-plugin-textdomain’ ),

‘not_found’          => __( ‘No shoes found.’, ‘your-plugin-textdomain’ ),

‘not_found_in_trash’ => __( ‘No shoes found in Trash.’, ‘your-plugin-textdomain’ )

);

$args = array(

‘labels’             => $labels,

‘public’             => true,

‘publicly_queryable’ => true,

‘show_ui’            => true,

‘show_in_menu’       => true,

‘query_var’          => true,

‘rewrite’            => array( ‘slug’ => ‘shoes’ ),

‘capability_type’    => ‘post’,

‘has_archive’        => true,

‘hierarchical’       => false,

‘menu_position’      => null,

‘supports’           => array( ‘title’, ‘editor’, ‘author’, ‘comments’ ) //remove comments

);

register_post_type( ‘shoes’, $args );

}

Method 3: Use remove_post_type_support() Hook

remove_post_type_support() Hook can be used to remove any type of functionality from your WordPress website. Here, we are using it to disable the comments functionality from your custom post type.

Add the following code snipped in your functions.php file:

add_action( ‘init’, ‘remove_custom_post_comment’ );

function remove_custom_post_comment() {

remove_post_type_support( ‘shoes’, ‘comments’ );

}

Hope you find this tutorial useful. If you have any other method of performing this job, don’t forget to share with us in the comments section below.

email

About jason

Jason is an expert WordPress developer having years of experience in working with various web development technologies. He is expert in converting PSD to WordPress. Currently, he is working for a leading WordPress development company - WordSuccor Ltd. He is always trying to share his intangible knowledge with others on the web.

Comments are closed.

Post Navigation