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

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.

Let a WordPress Expert help you

Do you want to try this, but feel like you need a helping hand, in case something goes wrong? My service, The WP Butler, gives you access to WordPress expertise whenever you need it. Better yet, I'll keep your site backed up, updated and secure, so that you don't have to worry about it. It's all part of the service. Use coupon DIWW and save 15% on all plans.

Visit The WP Butler

Author:

Dave has been tinkering with WordPress for many years, and he now shares his WordPress knowledge here on Do It WIth WordPress to help others realise its impressive power. He can also be hired to help with your WordPress needs. Dave, who is British, is married to his best friend, Marti, with whom he has a beautiful daughter, Ellie. When he's not dabbling with WordPress, he's probably eating Triscuits or hummus, watching an indie film or British TV show, spending time with friends or family, or 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