How to Create Custom RSS Feeds

RSS feeds are very versatile, they can be easily used to syndicate custom content to partner websites, rather than just posts.

Examples of sites which use RSS feeds in this way are iTunes and Flickr.

The question is how can you generate such custom feeds from your WordPress websites? Turns out there isn’t a plugin (ok, just one, that’s gone over 2 years without updating) that can help you out with this, you’ll have to do some diving into code or simply have one of our partners do it for you.

Lets Take a Deeper Dive

WordPress comes with built-in default RSS feeds. You can tweak the default feeds by adding custom content to your RSS Feeds, or even adding a post thumbnail to your RSS Feeds. The default RSS and Atom feeds are enough for most users, but you may wish to create a custom RSS feed for delivering specific type of content. In this article, we will show you how to create custom RSS feeds in WordPress.

Let’s assume you want to create a new RSS feed which displays just the following information:

  • Title
  • Link
  • Published Date
  • Author
  • Excerpt

First, you need to do is create the new RSS feed in your theme’s functions.php file or in a site-specific plugin:


The above code triggers the customRSS function, which adds the feed. The add_feed function has two arguments, feed name, and a callback function. The feedname will make up your new feed url and the callback function will be called to actually create the feed. Make a note of the feed name, as you’ll need this later on.Once you have initialized the feed, you’ll need to create the callback function to produce the required feed, using the following code in your theme’s functions.php file or in a site-specific plugin:


The code above is using the get_template_part function to link to a separate template file, however you can also place the RSS code directly into the function. By using get_template_part, we can keep the functionality separate to the layout.The get_template_part function has two arguments, slug and name, that will look for a template file with the name in the following format, starting with the file at the top (if it doesn’t find the first, it will move on to the second, and so on):

  1. wp-content/themes/child/rss-feedname.php
  2. wp-content/themes/parent/rss-feedname.php
  3. wp-content/themes/child/rss.php
  4. wp-content/themes/parent/rss.php

For the purposes of this tutorial, it is best to set the slug to the type of feed you’re creating (in this case: rss), and the name to the feedname configured earlier on.

Once you’ve told WordPress to look for the feed template, you’ll need to create it. The below code will produce the layout for the feed with the information we listed earlier. Save this file in your theme folder as the slug-name.php template file configured in the get_template_part function.

* Template Name: Custom RSS Template - Feedname
$postCount=5;// The number of posts to show in the feed
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"
        <atom:link href="<?phpself_link();?>"rel="self"type="application/rss+xml"/>
        <lastBuildDate><?phpechomysql2date('D, d M Y H:i:s +0000',get_lastpostmodified('GMT'),false);?></lastBuildDate>
                        <pubDate><?phpechomysql2date('D, d M Y H:i:s +0000',get_post_time('Y-m-d H:i:s',true),false);?></pubDate>
                        <guid isPermaLink="false"><?phpthe_guid();?></guid>

This template code will generate an RSS feed following the above layout. The postCountvariable allows you to control the number of posts to display in your feed. The template can be amended as required to display whatever information you require (e.g. post images, comments, etc).The the_excerpt_rss function will display the excerpt of each post, and for posts that do not have excerpts, it will display the first 120 words of the post’s content.

Finally, to display your feed, you’ll first need to flush your WordPress rewrite rules. The easiest way to do this is by logging in to the WordPress admin, and clicking Settings > Permalinks. Once here, just click Save Changes, which will flush the rewrite rules.

You can now access your new feed at, where feedname was the feedname you gave in the add_feed function earlier on.

The W3C offers a feed validation service, allowing you to validate the resulting feed.


  • I’m getting a 404 error when trying to view my feed!
    • Check to see if you are using the correct feedname in your URL. It has to be the one you supplied in the add_feedfunction
    • If you have the correct feedname, your rewrite rules may not have flushed correctly. Re-save your permalinks just to be sure.
    • If you’ve re-saved your permalinks, you can force a rewrite flush via your theme’s functions.php file. Add the following code to the customRSS function we created earlier. Make sure you add the code after the add_feed function.

      global $wp_rewrite;

      Once you’ve added this, reload your WordPress site. NOTE: This should be removed immediately after use. Once is enough for the rules to be flushed.

  • My feed isn’t validating!
    • Using the W3C feed validator, specific details should be given where your feed isn’t validating. Edit the feed template file to resolve these issues
  • I’m getting a <language /> validation error!
    • This is common where the RSS language has not been configured on your WordPress installation. To do this, you can add the following code to your theme’sfunctions.php file, to update the language option

    • Edit the second argument of the update_option function to change the language to one you require. Check out the full list of RSS Language Codes.
    • Once the above code has been added to your functions file, load the WordPress admin screen for it to take effect. After this, the code should be removed from your WordPress functions file. Loading it once is enough to configure the rss_language setting.
    • This can also be done directly in the database, by looking for the rss_language option in the wp_options table.

Source: WP Beginner

Still need help? Contact Us Contact Us