comment_text
commentsFilters the displayed text of a single comment
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.
Signature
apply_filters( 'comment_text', string $comment_text, WP_Comment|null $comment, array $args );Example
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 );Common Use Cases
- Add badges/labels to comment output
- Auto-link mentions or hashtags in comments
- Strip disallowed markup on display