LogMeIn
Thesis WordPress theme rocks

How to get Thesis Post Image and Multimedia Box content into the RSS feed

by justin on June 7, 2009 · 4 comments

If you’re a normal web citizen, this post will be insanely boring for you… so I suggest skipping it. But if you’re a WordPress blogger, especially a Thesis blogger who cares about your RSS feeds, you don’t want to miss it…

Intro to the Post and Multimedia boxes

I, like many other bloggers, am a big fan of the Thesis Theme by Chris Pearson. It gives me customization and styling options that I never thought possible with WordPress… and has catapulted me into a new era of webdesign. See, I stopped doing web design years ago when I got sick of tables and dreamweaver and the pain of making edits to my sites… I moved into Macintosh Consulting and Digital Life Coaching and love it. Lately, thoigh, I’ve rediscovered my love of creating websites becuase of, among other things, the Thesis Theme and the power I can harness therein.

Two of my favorite parts of Thesis are the “Post Image” and “Multimedia Box” fields. The Post Image field (used in this post for the yellow thesis image) really helps when using “Teasers” (the magazine-like blocks that my posts look like on the homepage) because it automatically crops this post image to a thumbnail size and displays it in the teaser. The Multimedia Box is similar because just by pasting a URL into the proper field I can “hook” into that box that sits at the top of my right column. (Which, for this post, is my default image. If there is demand for it, I’ll create a tutorial video for this slot and update this post)

The Problem

I won’t go into too much detail about the “Post” and “Multimedia” box Thesis features, but suffice it to say that they’re neat. Except if you want everything to show up in your RSS feed… because they don’t. They’re being added into the page by Thesis when it draws in your browser, but they aren’t considered part of the content of the post and therefore never get pushed to the RSS feed. Some people might not mind this and others will love it… but I hate it. The images I’m using for my post are important parts of the story and I’d hate for my email or RSS readers to miss them… so I went looking for a solution.

Though the wonderful Thesis community unfortunately didn’t have an answer for me… someone had linked to this WordPress plugin by Justin Tadlock called “Custom Fields for Feeds”.

Justin (a great name, by the way)’s plugin doesn’t work out of the box with Thesis’ built in fields. It requires some hacking… and thankfully he’s released it with the GPL license so I can happily and legally take his code and adapt it for Thesis…. here goes…

The Coding adventure. (or “The Solution”)

  1. The first thing (which is nice) is that we don’t have to use this as a plug-in. Thesis lets us insert custom functions with our custom_functions.php file instead. So I removed the plug in and pasted his php file into custom_functions.php. (being careful to remove the leading and trailing php commands)
  2. Second, his field names don’t match what Thesis is using so we have to edit this:

    // Checks to see if there's an image
    $image = get_post_meta($post->ID, 'Image', $single = true);
    $image_alt = get_post_meta($post->ID, 'Image Alt', $single = true);
    
  3. to replace “Image” with “thesis_post_image” and “Image Alt” with “thesis_post_image_alt”:

    // Checks to see if there's a Post Image
    $image = get_post_meta($post->ID, 'thesis_post_image', $single = true);
    $image_alt = get_post_meta($post->ID, 'thesis_post_image_alt', $single = true);
    
  4. That was easy… then I did the same thing for the Multimedia Box image fields, making them 2nd priority for inclusion on the RSS feed:

    // If there's a Multimedia Box Image
    if($image == '') {
    $image = get_post_meta($post->ID, 'thesis_image', $single = true);
    $image_alt = get_post_meta($post->ID, 'thesis_image_alt', $single = true);}
    
  5. … and again for Thumbnail images, being the 3rd priority:

    // If there's a Thumbnail
    if($image == '') {
    $image = get_post_meta($post->ID, 'thesis_thumb', $single = true);
    $image_alt = get_post_meta($post->ID, 'thesis_thumb_alt', $single = true); }
    
  6. Then I created some default alt text in case one of my images didn’t have one, and inserted that into his function:

    // If there's no "Image Alt," "Feature Image Alt," or "Thumbnail Alt"
    if($image_alt == '') { $image_alt = 'YOUR DEFAULT ALT TEXT GOES HERE'; }
    
  7. Also, I pulled out the extra fields he included which don’t match up with Thesis and aren’t necessary… and removed the video code, because I haven’t gotten that to work yet. (Still trying to make this work, so if any of you Ninjas out there have suggestions, I’d love to dig into this one with you)

    Finally, I put the hook code after the function instead of at the top where he had it: (though I’m not sure if this placement matters or not, I like it for consistency)

    add_filter('the_content', 'custom_fields_for_feeds');
    
  8. When I removed the video insert section I had to make the image insert section an “if” instead of an “elseif”… and it worked!

The Result… and caveats

Now, whenever I use the “Post Image” field, it shows up in my RSS feed at the top… and when I use the Multimedia Box it will show up if there is no Post image. I’m sure the code could be adjusted to include both… (or Chris Pearson could give us a UI to have preferences in Thesis 1.6) but that’s for a higher-level ninja than me. I’m totally content to have either/or.

The other thing to be aware of is that the original function worked with video too… and I could not get that to work for various technical reasons. If you’re interested in having your YouTube embed objects show up in your RSS feed (like I am) please comment below or email me.

So…. (drum roll please)…. Thesis users who want to have their Post Images and Multimedia Box Images added to the top of their RSS feeds may download the full function here. Then just copy and paste the entire contents of that text file into the bottom of your custom_functions.php!

Incidentally, I’m new to the Thesis community and this is my first contribution, so I want to say “thank you” to all of the bloggers who’ve written tutorials for me… and I hope this helps out some of you!


UPDATE: Sigh, this fix is now defunct if you’re using Thesis 1.5.1. They fixed this problem only days after my post… so… yay, good for them. **sigh**