This past weekend while attending WordCamp Utah, I was having lunch with a few of the other attendees who were both attending their first WordCamp events. I mentioned that Utah was roughly my 15th event over the past 2 years. One of them asked me, “Don’t they get repetitive?”, to which I answered, “Yes, but I still learn something new at every event I attend!” WordCamp Utah would be no different.
A quick bit of back story
I recently started a micro-photo-blog project over at VegasGeek.com using WooThemes and a couple plugins that make it simple to run the entire site from my phone. I snap the photo and send it as an email. A plugin called Postie checks a hidden email account once an hour and any new emails it receives it posts them to the site. Based on the way the theme works, the image gets saved as a custom field on each post. For visitors to the website, this isn’t a problem at all. But, for people who sign up via RSS, the image isn’t being attached. This has been driving me crazy!
WordCamp to the rescue
Saturday morning I sat in on Jake Spurlock‘s session where he was talking about the WordPress loop. During his session he mentioned a WordPress function called is_feed(). The lightbulb went on over my head and I knew I had the basis for my solution.
On Sunday as we waited at the airport for our plane back to Vegas, I cranked out a simple plugin to solve my problem. And here it is:
<?php
add_filter( 'the_content', 'jh_add_image');
function jh_add_image( $content) {
global $post;
if (is_feed()) {
$img = get_post_meta( $post->ID, 'image' );
$content = '<img src="'.$img[0].'"><br />'.$content;
}
return $content;
}
?>
Note: You don’t have to install this as a plugin, but could instead include this code in your theme’s functions.php file.
This is just one of the many reasons why I continue going to WordCamp events.
Thanks for sharing! It was really great meeting you and Todd this weekend. I learned a lot from your presentation as well.
I am excited to start using custom post types in my plugins.
Very cool…as you know, I was having the same issue. Thanks!
You run the entire photo site with your iPhone and a couple of plugins? I’m listening….