The get_comment_ID() WordPress PHP function retrieves the comment ID of the current comment.
Usage
$comment_id = get_comment_ID();
Parameters
- None
More information
See WordPress Developer Resources: get_comment_ID()
Examples
Display the comment ID
This example retrieves and displays the comment ID.
$comment_id = get_comment_ID(); echo "Comment ID: " . $comment_id;
Use the comment ID as an anchor
This example creates an anchor link with the comment ID.
$comment_id = get_comment_ID(); echo '<a href="#comment-' . esc_attr($comment_id) . '">Jump to comment ' . $comment_id . '</a>';
Create a div with a comment ID attribute
This example creates a div element with an ID attribute using the comment ID.
$comment_id = get_comment_ID(); echo '<div id="comment-' . esc_attr($comment_id) . '">Comment content</div>';
Delete a comment by its ID
This example deletes a comment by using its comment ID.
$comment_id = get_comment_ID(); wp_delete_comment($comment_id);
Update a comment by its ID
This example updates the comment content using the comment ID.
$comment_id = get_comment_ID(); $comment_data = array( 'comment_ID' => $comment_id, 'comment_content' => 'Updated comment content', ); wp_update_comment($comment_data);