Using WordPress ‘get_the_title_rss()’ PHP function

The get_the_title_rss() WordPress PHP function retrieves the current post title for the feed.

Usage

echo get_the_title_rss();

Parameters

  • None

More information

See WordPress Developer Resources: get_the_title_rss

Examples

Display Post Title in RSS Feed

Display the current post title in an RSS feed.

// Inside your RSS loop
echo '<item>';
echo '  <title>' . get_the_title_rss() . '</title>';
// Other RSS item elements
echo '</item>';

Filter Post Title for RSS Feed

Apply custom filter to modify the post title in an RSS feed.

// Inside your functions.php
function custom_title_rss($title) {
  return $title . ' - Custom Suffix';
}
add_filter('the_title_rss', 'custom_title_rss');

Create RSS Feed Template

Create a custom RSS feed template displaying the post title.

// Inside your custom RSS template
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>';
?>
<rss version="2.0">
  <channel>
    <?php while (have_posts()) : the_post(); ?>
      <item>
        <title><?php echo get_the_title_rss(); ?></title>
      </item>
    <?php endwhile; ?>
  </channel>
</rss>

Display Post Title with Custom Prefix in RSS Feed

Add a custom prefix to the post title in an RSS feed.

// Inside your RSS loop
echo '<item>';
echo '  <title>Custom Prefix: ' . get_the_title_rss() . '</title>';
// Other RSS item elements
echo '</item>';

Display Post Title and Categories in RSS Feed

Display the post title and categories in an RSS feed.

// Inside your RSS loop
echo '<item>';
echo '  <title>' . get_the_title_rss() . '</title>';
echo '  <category>' . get_the_category_rss() . '</category>';
// Other RSS item elements
echo '</item>';