Skip to content

Instantly share code, notes, and snippets.

@DeveloperWil
Last active October 6, 2020 08:14
Show Gist options
  • Select an option

  • Save DeveloperWil/fce020cfb5ec116cae3b29d08aaef80a to your computer and use it in GitHub Desktop.

Select an option

Save DeveloperWil/fce020cfb5ec116cae3b29d08aaef80a to your computer and use it in GitHub Desktop.
Add Featured Image To WP RSS Feed
<?php
//This will prepend your WordPress RSS feed content with the featured image
function wbd_featured_image_in_rss_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$prepend = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 10px;' ) ) . '</div>';
$content = $prepend . $content;
}
}
return $content;
}
add_filter('the_content', 'wbd_featured_image_in_rss_feed');
add_filter('the_excerpt_rss', 'wbd_featured_image_in_rss_feed');
add_filter('the_content_feed', 'wbd_featured_image_in_rss_feed');
@DeveloperWil
Copy link
Author

Add this to your theme's functions.php file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment