WordPress comment_text() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_text() prints the body of a comment, which is the message the visitor wrote.

It prints the text after WordPress filters have run. By default this turns blank lines into paragraphs and makes links clickable.

Syntax

Call it inside the comment loop, or pass a comment ID.

WordPress
comment_text();
comment_text( 15 );
CallWhat it does
comment_text()Prints the text of the current comment.
comment_text( 15 )Prints the text of comment 15.
get_comment_text()Returns the raw text without filters.

The output is wrapped in paragraph tags, for example <p>Great post!</p>.

Full declaration
WordPress
comment_text( int|WP_Comment $comment_id = 0, array $args = array() ): void

Parameters

ParameterDescription
$comment_idOptional. A comment ID or WP_Comment object. Default is the current comment.
$argsOptional. An array of arguments passed to the comment_text filter.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the comment text.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Basic use

Print the text in a comment callback.

WordPress
<div class="comment-content">
  <?php comment_text(); ?>
</div>

How It Works

  1. WordPress prints the saved message.
  2. The text is wrapped in a p tag.
  3. Your wrapper div is used for styling.

Example 2 — Awaiting moderation

Show a notice when the comment is not approved yet.

WordPress
<?php if ( '0' === $comment->comment_approved ) : ?>
  <p><em>Your comment is awaiting moderation.</em></p>
<?php endif; ?>
<?php comment_text(); ?>

How It Works

  1. $comment is passed to your callback.
  2. A value of 0 means the comment is waiting for approval.
  3. The text is printed after the notice.

Example 3 — Return value

Use get_comment_text() when you need a short plain text.

WordPress
<?php $text = get_comment_text(); ?>
<p><?php echo esc_html( wp_trim_words( $text, 10 ) ); ?></p>

How It Works

  1. get_comment_text() returns the raw text.
  2. wp_trim_words() keeps the first 10 words.
  3. esc_html() makes the result safe.

Frequently Asked Questions

It prints the body of the current comment after the comment_text filters run.
Yes. By default WordPress turns blank lines into paragraphs.
get_comment_text() returns the raw text. comment_text() prints the filtered text.
Use comment_excerpt().
Yes. WordPress cleans the text with its comment filters before it is printed.

Next: comment_text_rss()

Print the comment text in a form that is safe for an RSS feed.

comment_text_rss() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful