How has RSS helped you

How to create custom RSS feeds in WordPress

WordPress has built-in RSS feeds. You can tweak the standard feeds by adding custom content to your RSS feeds or even adding post thumbnails to your RSS feeds. The standard RSS and Atom feeds will do for most users. However, you can create a custom RSS feed to serve specific content. In this article, we are going to show you how to create custom RSS feeds in WordPress.

Please note that this tutorial is not intended for WordPress users. If you're a beginner and still want to try it out, do a local install.

As always, you need to take a full backup of your WordPress website before making any major changes to a live website.

Let's start with the first custom RSS feed in WordPress.

For example, suppose you want to create a new RSS feed that contains only the following information:

  • title
  • shortcut
  • Release date
  • author
  • abstract

The first thing you need to do is create the new RSS feed in your topic file or in a site-specific plugin:

add_action ('init', 'customRSS'); function customRSS () add_feed ('feedname', 'customRSSFunc');

The code above triggers the function that adds the feed. The add_feed function has two arguments, the feed name and a callback function. The feed name forms your new feed url. The callback function is called to actually create the feed. Make a note of the feed name as you will need it later.

After you have initialized the feed, you need to create the callback function to generate the required feed. To do this, use the following code in your topic file or in a site-specific plugin:

function customRSSFunc () get_template_part ('rss', 'feedname');

The above code uses the function to link to a separate template file, but you can also paste the RSS code directly into the function. By using it, we can keep the functionality separate from the layout. The function has two arguments, slug and name, which look for a template file with the name in the following format, starting with the file at the beginning (if it doesn't find the first, it will be forwarded to the second, and soon):

    In this tutorial, we recommend setting the slug to the feed type you created (in this case: rss) and the name to the feed name you configured earlier.

    Once you've told WordPress to look for the feed template, you'll need to create this one. The following code layouts the feed using the information listed earlier. Save this file in your design folder as a template file slug-name.php which is configured in the function file.

    This template code generates an RSS feed according to the layout above. This variable allows you to control the number of posts that should be displayed in your feed. The template can be modified as needed to show the information you want (e.g. post pictures, comments, etc).

    The feature shows the excerpt of each post, and for posts that do not contain any excerpts, the first 120 words of the post's content are shown.

    In order to view your feed, you first need to empty the WordPress rewrite rules. The easiest way to do this is to log into the WordPress administrator and click Settings -> Permalinks. Once you are here, just click save Changes, This clears the rewriting rules.

    You can now access your new feed, where Feed Name was the feed name you specified in the function used earlier.

    The W3C provides a feed validation service that you can use to validate the resulting feed.


    • I get a 404 error message when trying to view my feed!
      • Check that you are using the correct feed name in your URL. It has to be the one you have delivered in to feature
      • If you have the correct feed name, your rewrite rules may not have been properly flushed. Save your permalinks just to be safe.
      • If you have saved your permalinks again, you can force a rewrite process via the functions.php file of your topic. Add the following code to the customRSS function you created earlier. Make sure you add the code after the function.
      • global $ wp_rewrite; $ wp_rewrite-> flush_rules ();
      • When you've added this, reload your WordPress site. NOTE: This should be removed immediately after use. One time is enough to delete the rules.
    • My feed is not confirmed!
      • When using the W3C Feed Validator, specific details should be provided where your feed will not be validated. Edit the feed template file to resolve these issues
    • I get a validation error!
      • This is often the case if no RSS language has been configured in your WordPress installation. To do this, you can add the following code to your topic file to update the language option.
      • function rssLanguage () update_option ('rss_language', 'en'); add_action ('admin_init', 'rssLanguage');
      • Edit the second argument of the update_option function to change the language you want. See the full list of RSS Language Codes.
      • Once the above code has been added to your function file, load up the WordPress administration screen for it to take effect. After that, the code should be removed from your WordPress function file. A single load is sufficient to configure the setting of rss_language.
      • This can also be done directly in the database by looking for the rss_language option in the wp_options table.

    We hope this article has helped you create your own RSS feeds in WordPress. Let us know how and why you use custom RSS feeds on your WordPress site by leaving a comment below.