Title: get_comment_ID
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_comment_ID(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#wp--skip-link--target)

Retrieves the comment ID of the current comment.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#return)󠁿

 string The comment ID as a numeric string.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#source)󠁿

    ```php
    function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
    	$comment = get_comment();

    	$comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';

    	/**
    	 * Filters the returned comment ID.
    	 *
    	 * @since 1.5.0
    	 * @since 4.1.0 The `$comment` parameter was added.
    	 *
    	 * @param string     $comment_id The current comment ID as a numeric string.
    	 * @param WP_Comment $comment    The comment object.
    	 */
    	return apply_filters( 'get_comment_ID', $comment_id, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/comment-template.php#L727)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/comment-template.php#L727-L742)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_comment_ID’, string $comment_id, WP_Comment $comment )](https://developer.wordpress.org/reference/hooks/get_comment_id/)

Filters the returned comment ID.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  |

| Used by | Description | 
| [comment_form_title()](https://developer.wordpress.org/reference/functions/comment_form_title/)`wp-includes/comment-template.php` |

Displays text based on comment reply status.

  | 
| [comment_ID()](https://developer.wordpress.org/reference/functions/comment_id/)`wp-includes/comment-template.php` |

Displays the comment ID of the current comment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_comment_ID/?output_format=md#comment-content-3784)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_comment_id/#comment-3784)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_id%2F%23comment-3784)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_id%2F%23comment-3784)
 4. Example migrated from Codex:
 5. Uses the comment ID as an anchor id for a comment.
 6.     ```php
        <?php $comment_id = get_comment_ID(); ?>
    
        <div id="comment-<?php echo esc_attr( $comment_id ); ?>">Comment by 
        <?php comment_author() ?>: </div>
        <div class="comment-text"><?php comment_text() ?></div>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_id%2F%3Freplytocom%3D3784%23feedback-editor-3784)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_id%2F)
before being able to contribute a note or feedback.