Snippet: Better RSS Feeds (Removes Shortcodes & Displays Thumbnail)
// IMPORTANT: Use this function to clear your RSS cache so you can see your changes, then REMOVE it
function prefix_set_feed_cache_time( $seconds ) {
return 0;
}
add_filter( 'wp_feed_cache_transient_lifetime' , 'prefix_set_feed_cache_time' );
// Custom RSS feed
function my_custom_rss_feed( $content ) {
// Get post
global $post;
// Generate 50 word excerpt using the Total wpex_excerpt function
// This will strip out shortcodes from the Visual Composer
$content = wpex_get_excerpt( array(
'length' => 50,
'more' => false // remove hellip
) );
// Display post thumbnail if defined
if ( has_post_thumbnail( $post->ID ) ){
$content = get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . $content;
}
// Return the content
return $content;
}
add_filter( 'the_excerpt_rss', 'my_custom_rss_feed', 999 );
add_filter( 'the_content_feed', 'my_custom_rss_feed', 999 );
All PHP snippets should be added via child theme's functions.php file or via a plugin (we recommend WPCode)