Last active
July 25, 2017 18:38
-
-
Save lots0logs/0c5287b89312c0211dd4 to your computer and use it in GitHub Desktop.
WordPress :: Featured Image In RSS Feed For MailChimp
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
// 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