Title: get_comment_author
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_comment_author( int|WP_Comment $comment_id ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#changelog)

Retrieves the author of the current comment.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#description)󠁿

If the comment has an empty comment_author field, then ‘Anonymous’ person is assumed.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#parameters)󠁿

 `$comment_id`int|[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
optional

[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) or the
ID of the comment for which to retrieve the author.
 Default current comment.

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

 string The comment author

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

    ```php
    function get_comment_author( $comment_id = 0 ) {
    	$comment = get_comment( $comment_id );

    	if ( ! empty( $comment->comment_ID ) ) {
    		$comment_id = $comment->comment_ID;
    	} elseif ( is_scalar( $comment_id ) ) {
    		$comment_id = (string) $comment_id;
    	} else {
    		$comment_id = '0';
    	}

    	if ( empty( $comment->comment_author ) ) {
    		$user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
    		if ( $user ) {
    			$comment_author = $user->display_name;
    		} else {
    			$comment_author = __( 'Anonymous' );
    		}
    	} else {
    		$comment_author = $comment->comment_author;
    	}

    	/**
    	 * Filters the returned comment author name.
    	 *
    	 * @since 1.5.0
    	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
    	 *
    	 * @param string     $comment_author The comment author's username.
    	 * @param string     $comment_id     The comment ID as a numeric string.
    	 * @param WP_Comment $comment        The comment object.
    	 */
    	return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
    }
    ```

[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.1/src/wp-includes/comment-template.php#L24)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/comment-template.php#L24-L57)

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

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

Filters the returned comment author name.

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

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

Retrieves the translation of $text.

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

Retrieves user info by user ID.

  | 
| [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.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#)

| Used by | Description | 
| [WP_Comments_List_Table::column_comment()](https://developer.wordpress.org/reference/classes/wp_comments_list_table/column_comment/)`wp-admin/includes/class-wp-comments-list-table.php` |

Outputs the comment column.

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

Retrieves the current comment author for use in the feeds.

  | 
| [Walker_Comment::comment()](https://developer.wordpress.org/reference/classes/walker_comment/comment/)`wp-includes/class-walker-comment.php` |

Outputs a single comment.

  | 
| [Walker_Comment::html5_comment()](https://developer.wordpress.org/reference/classes/walker_comment/html5_comment/)`wp-includes/class-walker-comment.php` |

Outputs a comment in the HTML5 format.

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

Displays text based on comment reply status.

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

Retrieves HTML content for reply to comment link.

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

Retrieves the text of the current comment.

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

Displays the author of the current comment.

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

Retrieves the HTML link to the URL of the author of the current comment.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_comment_author/?output_format=md#)

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

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added the ability for `$comment_id` to also accept a [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) object. | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## User Contributed Notes

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