Add Custom Post Types to RSS Feed

RSS Feeds

Did you know that if you create a custom post type, it will not automatically be included in your site’s main RSS feed? That is because this feed is technically just a feed for posts that have the post_type post, which is fine for most sites since all posts are ‘posts’. (Try and make a sentence with more legitimate uses of the word post…).

However, if you start developing your site a little more and end up creating a custom post type, you’ll soon realise that your readers aren’t getting that information unless you intervene.

Fortunately, it’s a quick fix and it just requires a little snippet with very little customisation. Drop the following snippet into your functionality plugin and then add the custom post types to the array in line 5 as appropriate. You can add as many or as few as you want. In this example, I’ve added custom post types called gallery and product (note that you must leave post in there if you want to keep your posts in the RSS feed):

10 thoughts on “Add Custom Post Types to RSS Feed”

  1. Hi,
    Thanks for the info. You say to “drop the snippet into the functionality plugin.” Do you the functions.php file? If not, what’s the functionality plugin? I’ve been looking to put a custom post type into an rss feed for some time but couldn’t find out how to do it. Your article was on target for me. Thanks.

    1. The functions.php file will work well, but it’s bad practice. I try to encourage my readers to create a functionality plugin, which is more appropriate for things like this.

  2. Thanks for this Dave! Do you know of a good tutorial on creating a unique feed for your content type? For example, modifying the default feed to include custom fields, etc.

    1. Jack, I’m kind of confused… I think what you’re asking for is what this tutorial provides. Or are you asking for a unique feed that shows only posts from your custom post type?

      1. Sorry to be confusing; it’s a gift :-)
        I’m not talking about the main site feed. Each post type has it’s own unique feed and I would like to modify that feed by including custom fields. I’ve created a plugin to manage sermons using custom post types: http://www.wpforchurch.com/plugins/sermon-manager-plugin-for-wordpress/ I’d like to take the feed from my custom post type and include custom fields.

        1. OK, so you’re saying that in the post type’s unique feed you’d like the content to include custom fields in the content of the feed?

  3. Thank you for the code snippet. As custom post types will not be added automatically to RSS Feed, this information will be helpful.

  4. Gwen says:

    Hi there, was really happy to find this as I want to include both custom post types and pages into my RSS,

    After creating and activating the plugin I immediately got this error message:
    The plugin generated 235 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

    Naturally it is also now coming up on the top of my pages as well so I know I’ve missed a piece.

    After creating the functionality subfolder called gfm-functionality-plugin along with the gfm-functionality-plugin.php
    I placed the following code you supplied with changes I thought were appropriate:

    < ?php
    /*
    Plugin Name: Functionality Plugin for WordPress
    Plugin URI: http://gayfriendlymarket.com/
    Description: Moves most functions away from functions.php
    Author: M4 Group
    Version: 1.0
    Author URI: http://m4group.org
    License: GPL2
    */
    Am I missing something simple here?

    If I can get it sorted out then I would add the RSS code

    // ADD CUSTOM POST TYPES TO RSS FEED //

    function add_cpts_to_rss_feed( $args ) {
    if ( isset( $args['feed'] ) && !isset( $args['post_type'] ) )
    $args['post_type'] = array('post', 'directory', 'product');
    return $args;
    }

    add_filter( 'request', 'add_cpts_to_rss_feed' );

    I really want to do this for both custom posts and pages? Can you supply the correct code to include pages?

    Love that this could avoid another plugin, as I'm already over weighted on them.

    Thanks

    Gwen

    1. Hi Gwen,

      Well, at first glance, you’ve put a space in between the opening < and ? – it should be

  5. Gwen says:

    Hi Dave,
    Removing the space did the trick.
    Unfortunately all I see in the feed is the last 10 custom posts, whereas I have my RSS settings to show 100, which were all showing.

    Any idea why add the custom-post code would surpress my setting? Is there some switch I could add so that all 100 recent will show?

    Thanks,
    Gwen

Leave a Reply