setting comments off as default for pages and custom post types?

From what I understand, you want to set pages and some custom post types to have commenting ‘off’ by default, while posts will still use the default option (i.e. commenting ‘on’). If this is the case, the following function will do it.

function default_comments_off( $data ) {
    if( $data['post_type'] == 'page' && $data['post_status'] == 'auto-draft' ) {
        $data['comment_status'] = 0;
    }

    return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_off' );

Leave a Comment