How to Add Custom Post Types to RSS Feeds in WordPress

In order to add custom post types to your RSS Feeds copy the following code snippets and paste it inside your functions.php file located inside your theme’s folder.

function add_cpts_to_rss_feeds($query) {
	if (isset($query['feed']) && !isset($query['post_type']))
	{
                $query['post_type'] = get_post_types();
        }
	return $query;
}
add_filter('request', 'add_cpts_to_rss_feeds');

The above code will all the custom post types on your website to your RSS feeds.

Quick Tip: Time ago implementation in PHP

If you want to add only a specific posts to your RSS feeds use the following code snippet.

function add_cpts_to_rss_feeds($query) {
	if (isset($query['feed']) && !isset($query['post_type']))
        {
		$query['post_type'] = array('post','movie','show','song');
        }
	return $query;
}
add_filter('request', 'add_cpts_to_rss_feeds');

As you can see, along with default post we have added movie, show and song post types to the feeds.

Leave a Comment.