RSS Feeds

Add Custom Post Types to RSS Feed

| 10 Comments

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):

// 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', 'gallery', 'product');
  return $args;
}

add_filter( 'request', 'add_cpts_to_rss_feed' );

Categories: Code & Snippets | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Keep your site backed up, updated & secure

I provide a service called The WP Butler, which helps you stay on top of the maintenance of your WordPress site. Instead of worrying about whether your site is secure, updated and backed up, The WP Butler handles all that for you on a regular basis, so that you can focus on doing what you do best. If you use coupon DIWW, you'll save 15% on our already-low-prices for all maintenance plans.

Author: Dave Clements

Dave Clements has been building websites for close to a decade and in 2010, he formalised that by starting his own company, The UK Edge. He now works on a variety of web projects, from simple tasks like installing a new WordPress site, to consulting on problems, or redesigning his clients' sites. He also runs Do It With WordPress, a site dedicated to providing free tutorials on WordPress. When he's not building your new website, you can find Dave eating Wheat Thins, spending time with friends and family, watching Indie films, fostering kittens from the local Humane Society, listening to some dubstep, dance and electronic rock, and exploring the world.

10 Comments

  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.

  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.

  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. 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

  5. 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