Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add WordPress featured image to RSS feed

I'm setting up an RSS to email campaign in MailChimp using my WordPress RSS Feed, and I want to include the featured image in my MailChimp template. I've tried using this to add the image, which works, but it simply adds it to the content, which doesn't work for MailChimp section of the RSS code:

function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}

add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');

Apparently, MailChimp wants it's "own" unique image element. Here's an example of what they want: http://kb.mailchimp.com/article/how-can-i-format-the-image-content-in-my-rss-to-email-campaigns

but it looks like it's in a different RSS format. Here's what my RSS is outputting: http://pacmissions.org/dev/missions/zimbabwe-2012/feed/

like image 761
Adam Avatar asked Feb 03 '12 04:02

Adam


People also ask

How do I embed a featured image in WordPress?

Set a Featured ImageClick on the title of the page or post to open the editor. icon in the top right corner to make it appear. Click Set Featured Image as shown in the image on the right. You will then see options to choose an image from your site's Media Library, Google Photos, Pexels Free Photos, or Openverse.

Can RSS feeds have images?

Having an RSS feed with images will improve your syndication and may come in handy later since marketing tools like Mailchimp use RSS feeds to build newsletters. In this quick guide I'll show you how to display your featured image in the WordPress RSS feed using a plugin or with a functions.

How do I customize my WordPress RSS feed?

Edit Your RSS Feed Before and After Content Simply, click on the tag you want to add to the field and the link will be included in your feed. You can also type the hashtag character ( # ) in the field and it'll display a list of available tags you can choose from.

Can you add a link to a featured image in WordPress?

3. Now compose your post as usual and add the featured image. Then access the Custom Fields panel on your post page and 'Add New Custom Field' ExternalUrl and then add your desired destination external URL in the 'Value' entry like the below and that's it - your featured image will now link externally to the Link set.


1 Answers

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 ( http://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="http://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.

like image 110
Ash Avatar answered Oct 05 '22 17:10

Ash