RSS feed in mail chimp – featured images
-
Hi. I want to pull the featured image from wordpress into mail chimps automatic RSS feed newsletter service. I found this on Stack Overflow that seems to answer my question however I do not know where each piece of code mention here goes within WP?
I often have to create custom feeds for MailChimp, and find that a lot of the time I have to make somewhat ‘hacky’ changes like putting custom values into the limited standard fields that MailChimp supports.
Because of this I like to use the method described at Yoast (https://yoast.com/custom-rss-feeds-wordpress/) to create a page that outputs a custom RSS feed.
There are couple of tweaks to make in order to get the featured image included as a field that MailChimp will recognise.
Firstly you need to add the Media RSS namespace, which I usually do by adding to the opening <rss> tag:
<rss version="2.0" xmlns:media="https://search.yahoo.com/mrss">
Then in order to include the featured image inside the item:
<?php if(get_the_post_thumbnail()): ?> <media:content url="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>" medium="image" /> <?php endif; ?>
If you need to specify a particular image size to include, you’ll need to use this code inside the item instead:
<?php if(get_the_post_thumbnail()): ?> <media:content url="<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'imageSize'); echo $image[0]; ?>" medium="image" /> <?php endif; ?>
You can then grab this in MailChimp using the *|RSSITEM:IMAGE|* or *|FEEDITEM:IMAGE|* merge tags.
Thank you for your help.
- The topic ‘RSS feed in mail chimp – featured images’ is closed to new replies.