Skip to content

Instantly share code, notes, and snippets.

@lots0logs
Last active July 25, 2017 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lots0logs/0c5287b89312c0211dd4 to your computer and use it in GitHub Desktop.
Save lots0logs/0c5287b89312c0211dd4 to your computer and use it in GitHub Desktop.
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