Filter Hook since 0.71
comment_text
Filters the displayed text of a single comment
Description
comment_text is where you'd add nofollow to links, auto-linkify text, or moderate content on display — it doesn't change what's stored in the database.
When it runs
Each time comment_text() runs — usually inside wp_list_comments()'s callback.
Signature
apply_filters( 'comment_text', string $comment_text, WP_Comment|null $comment, array $args );Parameters
$comment_textstring — Comment content.$commentWP_Comment|null — The comment object.$argsarray — Arguments passed to comment_text().
Examples
Basic
add_filter( 'comment_text', function( $comment_text, $comment ) {
if ( $comment && ! $comment->user_id ) {
$comment_text .= '<span class="guest-badge">Guest</span>';
}
return $comment_text;
}, 10, 2 );Append a 'Guest' badge to comments from non-registered users.
Common Use Cases
- Add badges/labels to comment output
- Auto-link mentions or hashtags in comments
- Strip disallowed markup on display
Common mistakes
- Editing comment content here to 'fix' spam — this only changes display, not the stored comment; moderation belongs in preprocess_comment or comment status hooks
Related hooks
FAQ
Does filtering comment_text change the comment stored in the database?
No — it only changes what's rendered on display. The database row is untouched.
Source: wp-includes/comment-template.php