search ]

Enable Comments on Custom Post Types in WordPress

By default WordPress blocks comments on Custom Post Types. To enable comments on a custom post type, add comments under supports where you register it (line 32):

function snippet_custom_init() {
      $labels = array(
          'name' => 'Snippet',
          'singular_name' => 'Snippet',
          'add_new' => 'Add New Snippet',
          'add_new_item' => 'Add New Snippet',
          'edit_item' => 'Edit Snippet',
          'new_item' => 'New Snippet',
          'all_items' => 'All Snippets',
          'view_item' => 'View Snippet',
          'search_items' => 'Search Snippets',
          'not_found' =>  'No snippets found',
          'not_found_in_trash' => 'No snippets found in trash',
          'parent_item_colon' => '',
          'menu_name' => 'Snippets',
          );

      $args = array(
          'labels' => $labels,
          'exclude_from_search' => false,
          'public' => true,
          'publicly_queryable' => true,
          'show_ui' => true,
          'show_in_menu' => true,
          'query_var' => true,
          'rewrite' => array( 'slug' => 'snippet' ),
          'capability_type' => 'post',
          'has_archive' => true,
          'hierarchical' => false,
          'taxonomies' => array('category'),
          'menu_position' => null,
          'supports' => array( 'title', 'author', 'thumbnail', 'excerpt', 'comments', 'editor' )
          );

        register_post_type( 'snippet', $args );
    }
add_action( 'init', 'snippet_custom_init', 0);
Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo