Open Comments on Custom Post Types in WordPress

Updated 02/02/2024, Posted 02/02/2024 by James Parsons James Parsons 0 Comments

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 Snippets

Written by James Parsons

Hi, I'm James Parsons! I founded Content Powered, a content marketing agency where I partner with businesses to help them grow through strategic content. With nearly twenty years of SEO and content marketing experience, I've had the joy of helping companies connect with their audiences in meaningful ways. I started my journey by building and growing several successful eCommerce companies solely through content marketing, and I love to share what I've learned along the way. You'll find my thoughts and insights in publications like Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, and Inc, among others. I've been fortunate to work with wonderful clients ranging from growing businesses to Fortune 500 companies like eBay and Expedia, and helping them shape their content strategies. My focus is on creating optimized content that resonates and converts. I'd love to connect – the best way to contact me is by scheduling a call or by email.