Add Custom Post Types to Your RSS Feed

[ad_1]

WordPress has in-built RSS feed allowing visitors to subscribe. This RSS feed normally consist of just blog posts and it does not include custom post types in default RSS feed.

Although WordPress does not offer any setting to include custom post types in RSS feed, but we can modify the WordPress query to keep the default content type for blog posts “post” in the main RSS feed, and also add new custom post types.

This code snippet below will allow you to change the RSS feed to include all posts types in your feed.

// add all custom post types to rss feed
function wcs_all_cpt_in_feed( $vars ) {
    if ( isset( $vars['feed'] ) ) {
        $vars['post_type'] = get_post_types();
    }
    return $vars;
}
add_filter('request', 'wcs_all_cpt_in_feed');

Now if you check your RSS feed, you will notice all other posts types added to the feed.

But if you don’t want to display all custom post types in RSS feed but only want certain custom post types then you need to change the code and pass in an array of post types which you want to display in the RSS feed.

// add certain custom post types to rss feed
function wcs_certain_cpt_in_feed( $vars ) {
    $post_type_list = array( 'post', 'downloads' );
    if ( isset( $vars['feed'] ) AND !isset( $vars['post_type'] ) ) {
        $vars['post_type'] = $post_type_list;
    }
    return $vars;
}
add_filter('request', 'wcs_certain_cpt_in_feed');
[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads