Using WordPress ‘comment_author_rss’ PHP filter

The comment_author_rss WordPress PHP filter allows you to modify the current comment author’s information for use in a feed.

Usage

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

Parameters

  • $comment_author (string) – The current comment author’s name.

More information

See WordPress Developer Resources: comment_author_rss

Examples

Uppercase Comment Author Name

Convert the comment author’s name to uppercase.

add_filter('comment_author_rss', 'uppercase_comment_author');
function uppercase_comment_author($comment_author) {
    return strtoupper($comment_author);
}

Add Prefix to Comment Author Name

Add a prefix to the comment author’s name.

add_filter('comment_author_rss', 'add_prefix_comment_author');
function add_prefix_comment_author($comment_author) {
    return 'Author: ' . $comment_author;
}

Anonymize Comment Author Name

Replace the comment author’s name with “Anonymous.”

add_filter('comment_author_rss', 'anonymize_comment_author');
function anonymize_comment_author($comment_author) {
    return 'Anonymous';
}

Append Suffix to Comment Author Name

Add a suffix to the comment author’s name.

add_filter('comment_author_rss', 'add_suffix_comment_author');
function add_suffix_comment_author($comment_author) {
    return $comment_author . ' (Guest)';
}

Use Initials as Comment Author Name

Display only the initials of the comment author’s name.

add_filter('comment_author_rss', 'initials_comment_author');
function initials_comment_author($comment_author) {
    $name_parts = explode(' ', $comment_author);
    $initials = '';
    foreach ($name_parts as $part) {
        $initials .= substr($part, 0, 1) . '.';
    }
    return $initials;
}