How to add your custom post type to RSS feeds

How to add your custom post type to RSS feeds

in General

By default WordPress does not include custom post types in RSS feeds. Because of this, you need to add the post types to the query yourself.

You will add the following snippets to your theme’s (child theme recommended) functions.php file or if you want, to a custom plugin build just for your own website.

function my_custom_add_post_types_to_rss( $query ) {
// We do not want unintended consequences.
if ( ! $query->is_feed() ) {
return;
}

// Replace these slugs with the post types you want to include. As an example we have set up this for video and ts-recipe custom post
$custom_post_types = array( 'video', 'ts-recipe' );

$query->set(
  'post_type',
  array_merge(
    array( 'post' ),
    $custom_post_types
  )
);
}
add_filter( 'pre_get_posts', 'my_custom_add_post_types_to_rss' );

That should do it. Simply add this in the child theme’s functions.php file and you should be good to go.

0

0

Related Articles

Leave a Reply