• Hi there
    I recently summarised my feed however didn’t realise this would also remove all images. I would still like one image to be used as part of the summary – particularly for my RSS emails and on visual feed platforms like Bloglovin’.
    I have seen ways to set the post’s “featured image” to be served with the RSS however for various reasons I would prefer to use a different custom image.
    Does anyone know how to achieve this? I’ve searched though can’t find anything specific and as I’m not a developer I can’t figure it out on my own.
    Thanks so much for any advice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Adding a featured image to feeds involves hooking feed filters for excerpts or content and inserting an img tag in front of the passed content. The img src for featured images can be had with get_the_post_thumbnail_url(). If you want to use a different image, the same concept applies, but you need to get the proper image URL from somewhere. Where would such an URL reside?

    One way would be to get it from the attachment post type, but which attachment? Some posts have several, others none, despite having images in content. One option would be to specify the URL or attachment ID in a custom field for each post. If that’s the case, use get_post_meta() to retrieve the value and proceed from there.

    As a reminder, the feed filters for content and excerpts are ‘the_content_feed’ and ‘the_excerpt_rss’. Add a callback to these that inserts the img tag in front of the passed data.

    Thread Starter The Painted Hive

    (@the-painted-hive)

    Thanks so much. This helps a lot and I really appreciate your reply.
    So, I need to figure out how to tag/label (whatever it’s called) my specific images so they are grabbed for each post. Hmmm. I was hoping there was some way to add an image upload box to the post dash. You know, just like the “Featured Image” uploader that appears in the right side bar. I thought it would be cool to add an additional box that was the “RSS Image” uploader. Would this be possible?

    Moderator bcworkz

    (@bcworkz)

    Just about anything is possible with custom coding! You don’t even really need to manage uploads, images could be picked from the media library, which of course has an upload option. This saves you from needing to validate image files through your own means, the media library takes care of that.

    I’m not sure right now how to interface with the library, but the featured image meta box code can be used as a starting point, so that’s already established. It’s just a matter of storing the selection somewhere, just as the featured image is, only using a different key name.

    Meta boxes are added on /wp-admin/edit-form-advanced.php. There are action hooks to use in adding your own. The callback for the featured image box is post_thumbnail_meta_box(). You’ll see it mostly relies on a helper function. The link to that is in the “Uses” sub-section of the docs page.

    Get used to seeing featured image related code in core using “thumbnail” as the operative term. Featured images were initially called thumbnails, which caused a lot of confusion with unrelated thumbnail sized images, so the term was quickly updated, but the original terminology still persists in core code.

    If your new meta box fails to display on the edit screen, it may just need to be enabled through the screen options tab at upper right.

    Thread Starter The Painted Hive

    (@the-painted-hive)

    Wow, thank you so much. Great advice and info. Feeling confident I can implement this with just a bit more research. Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using Custom Post Images for RSS Feed’ is closed to new replies.