How to Create Custom RSS Feed in WordPress

How to Create Custom RSS Feeds in WordPress (2023 Guide)

RSS feeds are a convenient way for your audience to keep up with your latest WordPress content. While WordPress generates default RSS feeds out of the box, you may want more control over your feeds. Creating custom RSS feeds allows you to finetune exactly what content gets syndicated and how.

In this guide, you‘ll learn why custom RSS feeds are useful and get step-by-step instructions for creating your own custom feeds in WordPress. Let‘s dive in!

Understanding RSS Feeds in WordPress

RSS stands for Really Simple Syndication. An RSS feed is a structured XML file that contains your latest content in a standardized format. This allows users to subscribe to your feed using an RSS reader app and get notified whenever you publish new posts.

By default, WordPress creates an RSS feed for your entire site at yourdomain.com/feed. It also generates separate feeds for each author, category, tag, and comment section.

While these default feeds work great for most WordPress sites, there are a few reasons you might want to create a custom RSS feed:

  • Include only certain categories or tags in your feed
  • Exclude specific categories, authors, or post types from the feed
  • Provide separate feeds for custom post types
  • Create a feed with full post content (rather than just excerpts)
  • Build customized feeds for content syndication or to import into other platforms

For example, you could create a separate feed for a "News" category on your site, or set up a full-content feed designed for a service like Apple News.

Whatever your reasons, creating a custom RSS feed in WordPress is relatively straightforward. Here are two ways to set it up on your site.

Method 1: Creating a Custom RSS Feed using a Plugin

The safest and easiest way to create a custom RSS feed in WordPress is by using a plugin. This allows you to add the necessary custom code without directly editing your WordPress files.

We recommend using the free WPCode plugin to add custom code snippets to your site. Here‘s how to create a custom RSS feed with WPCode:

  1. Install and activate the free WPCode plugin.

  2. Go to Code Snippets → Add Snippet in your WordPress dashboard.

  3. Give your snippet a name (e.g. "Custom RSS Feed") and select "PHP Snippet" as the code type.

  4. Paste the following code into the snippet editor:

function custom_rss_feed() {
    add_feed(‘feedname‘, ‘custom_rss_feed_template‘);
}
add_action(‘init‘, ‘custom_rss_feed‘);

function custom_rss_feed_template() {
    get_template_part(‘rss‘, ‘feedname‘);
}

Make sure to replace feedname with the slug you want to use for your custom feed URL. For example, using podcast would make your feed available at yourdomain.com/feed/podcast.

  1. Below the code editor, set the Insertion location to "Auto Insert" and leave the other settings as-is.

  2. Publish your code snippet to activate the custom feed.

  3. Finally, go to Settings → Permalinks and click "Save Changes" to flush the WordPress rewrite rules and activate your new feed permalink.

That‘s it! Your custom RSS feed is now available at the URL you specified.

To customize what content is included in your feed, you‘ll need to create a custom RSS template file. Here‘s how:

  1. Create a new file in your current theme‘s folder named rss-feedname.php, replacing feedname with the feed slug you used earlier.

  2. Paste the following code into the file:

<?php
/**
 * Custom RSS template for [feedname]
 */

$postCount = 10; // The number of posts to include
$posts = get_posts(array(
    ‘numberposts‘ => $postCount,
    // Add custom query args here
));

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"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    <?php do_action(‘rss2_ns‘); ?>
>
<channel>
    <title><?php bloginfo_rss(‘name‘); ?> - Custom Feed</title>
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    <link><?php bloginfo_rss(‘url‘) ?></link>
    <description><?php bloginfo_rss(‘description‘) ?></description>
    <lastBuildDate><?php echo mysql2date(‘D, d M Y H:i:s +0000‘, get_lastpostmodified(‘GMT‘), false); ?></lastBuildDate>
    <language><?php bloginfo_rss(‘language‘); ?></language>
    <sy:updatePeriod><?php echo apply_filters(‘rss_update_period‘, ‘hourly‘); ?></sy:updatePeriod>
    <sy:updateFrequency><?php echo apply_filters(‘rss_update_frequency‘, 1); ?></sy:updateFrequency>
    <?php do_action(‘rss2_head‘); ?>
    <?php foreach ($posts as $post) : ?>
        <item>
            <title><?php echo get_the_title($post); ?></title>
            <link><?php echo get_permalink($post); ?></link>
            <pubDate><?php echo mysql2date(‘D, d M Y H:i:s +0000‘, get_post_time(‘Y-m-d H:i:s‘, true, $post), false); ?></pubDate>
            <dc:creator><?php echo get_the_author_meta(‘display_name‘, $post->post_author); ?></dc:creator>
            <guid isPermaLink="false"><?php echo get_the_guid($post); ?></guid>
            <description><![CDATA[<?php echo get_the_excerpt($post); ?>]]></description>
            <content:encoded><![CDATA[<?php echo apply_filters(‘the_content‘, get_post_field(‘post_content‘, $post)); ?>]]></content:encoded>
            <?php do_action(‘rss2_item‘); ?>
        </item>
    <?php endforeach; ?>
</channel>
</rss>

This template includes the basic structure for an RSS feed. You can customize the query arguments passed to get_posts() to change what content is included.

For example, here‘s how you would modify the query to only include posts from a "News" category:

$posts = get_posts(array(
    ‘numberposts‘ => $postCount,
    ‘category_name‘ => ‘news‘,
));

The template also demonstrates how to include full post content using get_post_field() instead of excerpts. You can further customize your feed as needed.

  1. Upload the rss-feedname.php file to your WordPress theme folder using FTP or via the Theme Editor in your dashboard.

Your custom RSS feed is now fully functional! Feel free to test it in an RSS reader app or using an online RSS validator.

Method 2: Directly Edit functions.php

An alternative method is to directly add the custom feed code to your active theme‘s functions.php file. This is riskier as any mistake can break your site, so be sure to make a complete backup first.

Here are the steps to register a custom RSS feed in functions.php:

  1. Access your WordPress files via FTP or SSH and navigate to the /wp-content/themes/your-theme/ directory.

  2. Download a copy of the functions.php file to use as a backup.

  3. Open functions.php for editing and paste the following code at the end of the file:

function custom_rss_feed() {
    add_feed(‘feedname‘, ‘custom_rss_feed_template‘);
}
add_action(‘init‘, ‘custom_rss_feed‘);

function custom_rss_feed_template() {
    get_template_part(‘rss‘, ‘feedname‘);
}

Replace feedname with your desired URL slug.

  1. Save your changes to functions.php and re-upload it to the server, overwriting the existing file.

  2. Go to Settings → Permalinks and click "Save Changes" to update the WordPress rewrite rules.

  3. Create a rss-feedname.php template file in your theme just like in the plugin method above.

Your custom RSS feed should now be accessible at yourdomain.com/feed/feedname.

7 Ideas for Useful Custom RSS Feeds

Not sure what kind of custom RSS feeds to make for your WordPress site? Here are a few ideas to get you started:

  1. Category or Tag Feeds – Create separate RSS feeds for each category or tag to let users follow only the topics they‘re interested in. You could have a "WordPress Tips" feed, a "Recipes" feed, and so on.

  2. Author Feeds – Give each of your authors their own dedicated RSS feed that includes only their posts. This is great for multi-author blogs or news sites.

  3. Curated Content Feeds – Set up RSS feeds that aggregate hand-picked posts from multiple categories. For example, a "Staff Favorites" feed featuring your best content.

  4. Post Type Feeds – If you use custom post types like portfolio items or products, give them each their own separate RSS feed to keep those updates distinct.

  5. Audio or Video Feeds – Build RSS feeds designed for your podcast episodes or video content, with full media enclosures to make them work well in podcast apps.

  6. Filtered Feeds – Exclude specific categories or post types to provide a more focused RSS feed for your audience. A "Blog Posts Only" feed that filters out your podcast episodes, for example.

  7. Full Content Feeds – Most default WordPress RSS feeds only include a post excerpt. You can create full-text RSS feeds that contain the entire post content for readers who prefer that.

The great thing about custom RSS feeds is you have complete control. You can mix and match the criteria to create any kind of custom feed your site needs.

Tips for Optimizing Your Custom RSS Feeds

Once you‘ve created a few custom RSS feeds, here are some tips to make sure they‘re working well for your audience:

  • Validate your feed – Use an online RSS validator to check for any errors in your feed and make sure it‘s working properly.
  • Brand your feed – Consider using FeedBurner to add your site logo and custom branding to your RSS feeds. This looks more professional than a plain XML file.
  • Promote your feeds – Don‘t forget to link to your custom RSS feeds so visitors can easily find and subscribe! Put prominent links in your sidebar, footer, or header.
  • Use RSS auto-discovery – Make sure your custom feed URLs are included in your site‘s <head> tag so browser RSS detection will pick them up.
  • Keep an eye on your feed stats – FeedBurner and many email marketing platforms provide analytics on your RSS subscriber count. Check in regularly to see how your custom feeds are doing.
  • Provide email subscription options – Many people prefer to receive RSS content via email. Consider providing an email signup for your custom feeds using a service like MailChimp or ConvertKit.

Creating custom RSS feeds does take a little work upfront, but the payoff is you can deliver your content to subscribers exactly how you want.

The Future of RSS

You might be wondering, are RSS feeds still relevant today? Absolutely.

While RSS may not be as dominant as it was in the heyday of Google Reader, it‘s still a widely-used standard for syndicating content across the web. Millions of people use RSS reader apps to follow their favorite sites and podcasts.

RSS is also an essential part of many content platforms, from podcast directories to news aggregators to research databases. Apple News, for instance, requires publishers to provide RSS feeds for their content.

So while RSS might not get the buzz it used to, it‘s still a powerful tool for reaching new audiences and keeping your existing subscribers engaged. Creating custom RSS feeds for your WordPress site is one of the best ways to take advantage of this technology.

With the methods outlined above, you can build custom RSS feeds tailored to your exact needs, whether that‘s filtered category feeds, full-content feeds for other platforms, or dedicated feeds to highlight your best stuff.

The WordPress community has also continued to embrace RSS, with new plugins and tools to extend the built-in feed functionality. For example, the free Feedzy RSS Feeds plugin makes it easy to import and display RSS content from other sites in WordPress.

It‘s safe to say RSS will be sticking around for the foreseeable future. By mastering custom RSS feeds for your WordPress site now, you‘ll be well-positioned to take advantage of its possibilities in the years to come.

Did you like this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.