Open Comments on Custom Post Types in WordPress

James Parsons by James Parsons Updated Feb 2nd, 2024

I noticed some custom post types will have comments disabled by default in WordPress, despite them being enabled globally.

To fix this, you can add the following to your functions.php file in your theme:

/*
 * Enable comments for "your_post_type_here" custom post type
 */ 

function enable_comments_on_code_post_type_save( $post_ID, $post, $update ) {
  if ( 'your_post_type_here' === $post->post_type && !wp_is_post_autosave( $post_ID ) ) {
      remove_action( 'save_post', 'enable_comments_on_code_post_type_save', 10, 3 );
      wp_update_post( [
          'ID'             => $post_ID,
          'comment_status' => 'open',
      ] );
      add_action( 'save_post', 'enable_comments_on_code_post_type_save', 10, 3 );
  }
}
add_action( 'save_post', 'enable_comments_on_code_post_type_save', 10, 3 );

Just remember to replace the two "your_post_type_here" instances above with the name of your post type.

How does this work?

Every time you save or publish a new post with your custom post type, this code checks to make sure that comments on that post are enabled.

Will it work retroactively on old posts?

No. You'll have to make a small modification to each posts. You can select multiple posts with the batch editor in the WordPress post list and make a change to all of them. For example, change the author from Author A to Author B, and then back to Author A. This will trigger an update on all of your posts and comments will be enabled on all of them. Moving forward, all new posts will have comments enabled automatically.

Related Code Entries

Written by James Parsons

James Parsons is the founder and CEO of Content Powered, a premier content marketing agency that leverages nearly two decades of his experience in content marketing to drive business growth. Renowned for founding and scaling multi-million dollar eCommerce businesses through strategic content marketing, James has become a trusted voice in the industry, sharing his insights in Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, Inc, and other leading publications. His background encompasses key roles across various agencies, contributing to the content strategies of major brands like eBay and Expedia. James's expertise spans SEO, conversion rate optimization, and effective content strategies, making him a pivotal figure in the industry.