Using WordPress ‘comment_text_rss’ PHP filter

The comment_text_rss WordPress PHP filter allows you to modify the content of the current comment for use in a feed.

Usage

add_filter('comment_text_rss', 'your_custom_function');
function your_custom_function($comment_text) {
    // your custom code here
    return $comment_text;
}

Parameters

  • $comment_text (string) – The content of the current comment.

More information

See WordPress Developer Resources: comment_text_rss

Examples

Remove HTML tags from comment content in RSS feed

Strip HTML tags from the comment content to display plain text in the RSS feed.

add_filter('comment_text_rss', 'strip_html_tags_from_comments');
function strip_html_tags_from_comments($comment_text) {
    $comment_text = strip_tags($comment_text);
    return $comment_text;
}

Limit comment length in RSS feed

Truncate comments to a maximum of 100 characters in the RSS feed.

add_filter('comment_text_rss', 'limit_comment_length');
function limit_comment_length($comment_text) {
    $max_length = 100;
    if (strlen($comment_text) > $max_length) {
        $comment_text = substr($comment_text, 0, $max_length) . '...';
    }
    return $comment_text;
}

Add a custom prefix to comment content in RSS feed

Add a custom prefix to each comment displayed in the RSS feed.

add_filter('comment_text_rss', 'add_custom_prefix_to_comments');
function add_custom_prefix_to_comments($comment_text) {
    $prefix = 'Comment: ';
    $comment_text = $prefix . $comment_text;
    return $comment_text;
}

Replace specific words in comment content for RSS feed

Replace specific words in the comment content before displaying them in the RSS feed.

add_filter('comment_text_rss', 'replace_specific_words_in_comments');
function replace_specific_words_in_comments($comment_text) {
    $search = array('badword1', 'badword2');
    $replace = array('****', '****');
    $comment_text = str_replace($search, $replace, $comment_text);
    return $comment_text;
}

Convert comment content to uppercase in RSS feed

Change the comment content to uppercase before displaying it in the RSS feed.

add_filter('comment_text_rss', 'convert_comments_to_uppercase');
function convert_comments_to_uppercase($comment_text) {
    $comment_text = strtoupper($comment_text);
    return $comment_text;
}