Skip to content

Instantly share code, notes, and snippets.

@duogeekdev duogeekdev/code.php
Last active Jan 23, 2017

Embed
What would you like to do?
Add featured image in rss feed in a wordpress site
<?php
function add_featured_image_in_rss() {
if ( function_exists( 'get_the_image' ) && ( $featured_image = get_the_image('format=array&echo=0') ) ) {
$featured_image[0] = $featured_image['url'];
} elseif ( function_exists( 'has_post_thumbnail' ) and has_post_thumbnail() ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'post-thumbnail' );
} elseif ( function_exists( 'get_post_thumbnail_src' ) ) {
$featured_image = get_post_thumbnail_src();
if ( preg_match( '|^<img src="([^"]+)"|', $featured_image[0], $m ) )
$featured_image[0] = $m[1];
} else {
$featured_image = false;
}
if ( ! empty( $featured_image ) ) {
echo "\t" . '<enclosure url="' . $featured_image[0] . '" />' . "\n";
}
}
add_action( 'rss2_item', 'add_featured_image_in_rss' );
@mathewnephews

This comment has been minimized.

Copy link

mathewnephews commented Apr 21, 2016

Hello,
I use the add_featured_image_in_rss function ...
When I use it in the function-file of my theme it works correct, but when I use it as a plugin through the mu-plugins-folder, it adds a blank line in front of the xml-declaration …
Any idea how to solve that?

Greetings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.