Example 1 — Basic use
Print the IP address of a comment.
<p>IP: <?php comment_author_IP(); ?></p> How It Works
- The function prints the saved IP address.
- It reads the current comment.
- The output is plain text.

In WordPress, comment_author_IP() prints the IP address that was used when the comment was sent.
It prints the IP as plain text. It helps moderators find spam. It is not meant for public pages.
Call it inside the comment loop, or pass a comment ID. The PHP name has a capital IP.
comment_author_IP();
comment_author_IP( 15 ); | Call | What it does |
|---|---|
comment_author_IP() | Prints the IP of the current comment author. |
comment_author_IP( 15 ) | Prints the IP of comment 15. |
get_comment_author_IP() | Returns the IP instead of printing it. |
The tutorial URL uses lowercase letters, but the PHP function name is comment_author_IP().
comment_author_IP( int|WP_Comment $comment_id = 0 ): void | Parameter | Description |
|---|---|
$comment_id | Optional. A comment ID or a WP_Comment object. Default 0, which means the current comment. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the IP address. |
Three short theme examples. Each one has a sample output.
Print the IP address of a comment.
<p>IP: <?php comment_author_IP(); ?></p> Show the IP only to people who can moderate comments.
<?php if ( current_user_can( 'moderate_comments' ) ) : ?>
<small>IP: <?php comment_author_IP(); ?></small>
<?php endif; ?> current_user_can( 'moderate_comments' ) checks the role.Use get_comment_author_IP() to work with the value.
<?php $ip = get_comment_author_IP(); ?>
<code><?php echo esc_html( $ip ); ?></code> get_comment_author_IP() returns the IP as a string.esc_html() makes it safe to print.Print the commenter's name as a link to their website.
12 people found this page helpful