The comment_text_rss()
WordPress PHP function is used to display the current comment content for use in the feeds. It takes no parameters.
Usage
To use comment_text_rss()
, simply call it within the loop in your RSS template. The function will automatically output the comment content, preformatted for RSS use.
while ( have_comments() ) : the_comment(); comment_text_rss(); endwhile;
In the above example, it will display all comments for a post in an RSS format.
Parameters
- None
More information
See WordPress Developer Resources: comment_text_rss()
This function is implemented in WordPress 1.5.0 and is not yet depreciated. The source code for the function can be found in wp-includes/comment-template.php
. Related functions include get_comment_text()
, comment_text()
and the_comment()
.
Examples
Displaying comments in RSS for a specific post
You can use the comment_text_rss()
function to display all comments for a specific post in an RSS format.
// Get comments for a post. $comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); // Loop through each comment. foreach ( $comments as $comment ) { // Set the global comment variable. $GLOBALS['comment'] = $comment; // Display the comment text. comment_text_rss(); }
Displaying comments with a custom wrapper
You can customize the output of comment_text_rss()
by wrapping it in custom HTML.
while ( have_comments() ) : the_comment(); echo '<div class="comment-rss">'; comment_text_rss(); echo '</div>'; endwhile;
Trimming comment output
You can limit the amount of text that comment_text_rss()
outputs by using the wp_trim_words()
function.
while ( have_comments() ) : the_comment(); $comment_rss = get_comment_text(); echo wp_trim_words( $comment_rss, 20, '...' ); endwhile;
Combining comment_text_rss()
with comment_author_rss()
Display the comment author’s name along with the comment text.
while ( have_comments() ) : the_comment(); comment_author_rss(); echo ': '; comment_text_rss(); endwhile;
Combining comment_text_rss()
with comment_date_rss()
Display the comment date along with the comment text.
while ( have_comments() ) : the_comment(); comment_date_rss(); echo ': '; comment_text_rss(); endwhile;
Remember, comment_text_rss()
should be used within the loop in your RSS template to ensure it has access to the correct comment data.