Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress :: Featured Image In RSS Feed For MailChimp
// add the namespace to the RSS opening element
function add_media_namespace() {
echo 'xmlns:media="http://search.yahoo.com/mrss/"\n';
}
add_action( 'rss2_ns', 'add_media_namespace' );
function add_featured_image_in_rss() {
$featured_image = false;
if ( has_post_thumbnail() ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'post-thumbnail' );
}
if ( false !== $featured_image ) {
echo "\t" . '<media:content url="' . $featured_image[0] . '" medium="image" />' . "\n";
}
}
add_action( 'rss2_item', 'add_featured_image_in_rss' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment