Add Custom Post Types to the RSS Feed
Includes entries from custom post types in the main RSS feed along with regular posts.
Opens WPIDE on
Code
add_filter( 'request', function ( $query_vars ) {
if ( isset( $query_vars['feed'] ) && ! isset( $query_vars['post_type'] ) && ! isset( $query_vars['withcomments'] ) ) {
$query_vars['post_type'] = array( 'post', 'portfolio' );
}
return $query_vars;
} );
Notes
Replace portfolio with your post type names.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.