Using WordPress ‘post_comment_status_meta_box()’ PHP function

The post_comment_status_meta_box WordPress PHP function displays the comments status form fields for a specific post.

Usage

post_comment_status_meta_box( $post );

Example:

// Assuming $post is the current post object
post_comment_status_meta_box( $post );

Parameters

  • $post (WP_Post): Required. The current post object.

More information

See WordPress Developer Resources: post_comment_status_meta_box

Examples

Display comment status meta box in a custom meta box

function my_custom_meta_box() {
global $post;
post_comment_status_meta_box( $post );
}
add_action('add_meta_boxes', 'my_custom_meta_box');

In this example, we create a custom meta box that displays the comment status form fields.

Replace the default comment status meta box with a custom one

function replace_comment_status_meta_box() {
remove_meta_box('commentstatusdiv', 'post', 'normal');
add_meta_box('commentstatusdiv', __('Comments'), 'my_custom_meta_box', 'post', 'normal', 'core');
}
add_action('admin_menu', 'replace_comment_status_meta_box');

function my_custom_meta_box() {
global $post;
post_comment_status_meta_box( $post );
}

In this example, we replace the default comment status meta box with a custom one.

Display the comment status form fields in a custom location

function display_comment_status_form_fields() {
global $post;
post_comment_status_meta_box( $post );
}
add_action('edit_form_after_title', 'display_comment_status_form_fields');

In this example, we display the comment status form fields in a custom location on the edit post screen, right after the post title.

Add the comment status form fields to a custom post type

function add_comment_status_form_fields_to_cpt() {
add_meta_box('commentstatusdiv', __('Comments'), 'post_comment_status_meta_box', 'my_custom_post_type', 'normal', 'core');
}
add_action('add_meta_boxes', 'add_comment_status_form_fields_to_cpt');

In this example, we add the comment status form fields to a custom post type named ‘my_custom_post_type’.

Add the comment status form fields to all public post types

function add_comment_status_form_fields_to_all_public_post_types() {
$post_types = get_post_types( array( 'public' => true ) );
foreach ( $post_types as $post_type ) {
add_meta_box('commentstatusdiv', __('Comments'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
}
}
add_action('add_meta_boxes', 'add_comment_status_form_fields_to_all_public_post_types');

In this example, we add the comment status form fields to all public post types.