Display custom field images in RSS Feeds

Result in Google Reader

If you’re reading this, I guess you know how frustrating it is when custom field images don’t display in your RSS Feed. This is because the feed only outputs your actual “content” by default (as in what you write in the editor), but not custom fields.

For example, if you take a look at this theme page on this site, you’ll notice the “features” box – that is done through custom fields. Now if you check it out in your RSS reader, that box will not appear, simply because RSS feeds don’t display custom fields by default.

The workaround

Lucky us, Justin Tadlock has created a simple but effective WordPress plugin that solves the problem.

Download the plug-in here.

Installation and set-up

  1. Extract the plugin to a folder and open the custom-fields-for-feeds.php file in your editor of choice.
  2. Delete all and and paste the following code:
ID, 'post_image_url', $single = true);
	$image_alt = get_post_meta($post->ID, 'post_image_alt', $single = true);
	$image_width = get_post_meta($post->ID, 'post_image_width', $single = true);
	$image_height = get_post_meta($post->ID, 'post_image_height', $single = true);	
 
// If there's an image, display the image with the content
// Feel free to change the styling of the image border
	if($image !== '') {
	$content = '
 
	<img src="'.$image.'" alt="'.$image_alt.'" width="'.$image_width.'" height="'.$image_height.'" />
 
' . $content;
	return $content;
	} // End if image
 
// If there's not an image, just display the content
	else {
	$content = $content;
	return $content;
	}
} // End function
?&gt;

Save, then upload and activate the plugin.

Now, when creating a post and assigning an image through custom fields, just use the values you specified earlier:

  • post_image_url = the absolute URL to the image (ex. http://www.mysite.com/wp-content/uploads/…..)
  • post_image_alt = the ALT text for the image (for accessibility and a little SEO)
  • post_image_width = the width of the image in pixels (ex. 600)
  • post_image_height = the height of the image in pixels(ex. 400)

Why I advised in step 2 to delete everything? Well, Justin’s awesome plug-in handles much more than just images, but it can get a little confusing if you only need images to show up. Consider it a “simplified” version.

Thanks Justin for the plugin!

    Please share it if you liked it:



Related Posts

  1. Display ads in WordPress depending on what site the visitor comes from
  2. WordPress Ecommerce Plugin – PHPurchase
  3. Wordpress Membership Plugins and Resources
  4. WordPress Ecommerce Plugins, Themes and Tutorials
  5. How to remove title tags in WordPress

2 Comments For This Post

  1. Norbert

    So it is possible to theoreticly any custom field value to a rss-feed. But have you any idea how to read out a single custom field value from a rss-feed instead of (only) recieving it with the content?
    Thanks you very much for sharing

  2. ThemeDigital

    Hey Norbert,

    Thanks, glad you found it helpful :)

    Not sure I understand your question, can you please elaborate on “read out a single custom field”?

    Cheers!

What do you think of this?