Last active
March 6, 2024 17:23
-
-
Save someguy9/7dd3117978542fa744d60acbf12b82ab to your computer and use it in GitHub Desktop.
Display Featured Image in WordPress RSS Feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//This will prepend your WordPress RSS feed content with the featured image | |
add_filter('the_content', 'smartwp_featured_image_in_rss_feed'); | |
function smartwp_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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment