Created
November 20, 2023 17:32
-
-
Save wpgaurav/3f22a94e14a7fc71bdce665748897a7a to your computer and use it in GitHub Desktop.
Add featured image to 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 | |
/** | |
* Adds a featured image to RSS feeds. | |
* | |
* @param string $content The content of the post. | |
* @return string Modified content with featured image. | |
*/ | |
function prefix_featured_to_rss( $content ) { | |
global $post; | |
if ( has_post_thumbnail( $post->ID ) ) { | |
$thumbnail = get_the_post_thumbnail( $post->ID, 'large', array( 'style' => 'margin-bottom: 15px;' ) ); | |
$content = '<div>' . $thumbnail . '</div>' . $content; | |
} | |
return $content; | |
} | |
add_filter( 'the_excerpt_rss', 'prefix_featured_to_rss' ); | |
add_filter( 'the_content_feed', 'prefix_featured_to_rss' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment