wordpress featured image

Status: Open · Asked by serwar habib on · 0 views

serwar habib — Question ·
how to extract the featured image from rss feed in wordpress
James Smith — Reply ·

If your WordPress RSS feed includes the featured image, you can extract it in a few different ways depending on how the image is exposed.

Option 1: Featured image in <media:content> (recommended)

Many WordPress RSS feeds include the featured image as a media:content element.

Example RSS:

<item>
    <title>My Post</title>
    <media:content
        url="https://example.com/wp-content/uploads/image.jpg"
        medium="image" />
</item>

PHP:

$xml = simplexml_load_file($feedUrl);

foreach ($xml->channel->item as $item) {
    $media = $item->children('media', true);

    if (isset($media->content)) {
        $featuredImage = (string) $media->content->attributes()->url;
        echo $featuredImage;
    }
}

Option 2: Featured image in <media:thumbnail>

Some plugins output thumbnails instead.

$media = $item->children('media', true);

if (isset($media->thumbnail)) {
    $featuredImage = (string) $media->thumbnail->attributes()->url;
}

Option 3: Extract from the description/content

If the feed doesn't expose media tags, the first image may be inside the HTML.

$content = (string)$item->description;

preg_match('/<img[^>]+src="([^">]+)"/i', $content, $matches);

if (!empty($matches[1])) {
    $featuredImage = $matches[1];
}

Option 4: Enable featured images in your WordPress RSS feed

By default, WordPress does not include the featured image in RSS. You can add it by adding the following to your theme's functions.php or a custom plugin:

function add_featured_image_to_rss($content) {
    global $post;

    if (has_post_thumbnail($post->ID)) {
        $content = get_the_post_thumbnail($post->ID, 'full') . $content;
    }

    return $content;
}

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

Or, for better compatibility with RSS readers, output a proper media:content element using a plugin or custom RSS template.

Pabbly Support — Reply ·

Hi there,

Thanks for reaching out. To set a featured image on a WordPress post from an RSS feed item in Pabbly Connect, the recommended approach is:

1. Use the RSS Feed (New Feed) step as your trigger to capture new posts.
2. Add a WordPress: Upload Media (Beta) action before the Create a Post action. This uploads the image and returns a media ID in its response.
3. Map that returned media ID into the Featured Media ID field of the WordPress: Create a Post action.

A couple of important notes:
- The WordPress connection must use the official Basic Authentication plugin (not JSON Basic Auth, Mini Orange, or similar), otherwise the Upload Media step will fail with permission errors.
- The Author field in Create a Post must be a numeric user ID (e.g. 1), not a username.

The part I want to clarify: are you asking specifically how to pull/extract the image URL that comes back in the RSS feed response so you can feed it into the Upload Media step?
For this you would have to share the Workflow URL where you have setup RSS (Pabbly) as your trigger step.

Thanks & Regards,
Arshil Ahmad
🌐 Pabbly.com
Pabbly Support — Reply ·

Just following up regarding this—please share the Workflow URL where you've configured the RSS Feed trigger so we can check how the image URL is being returned and guide you accordingly.

Thanks & Regards,
Arshil Ahmad
🌐 Pabbly.com
Pabbly Support — Reply ·

Hello Serwar,

I hope you’re doing well. I just wanted to follow up regarding our last message.

Thanks & Regards,

Adeel Akhtar
🌐 Pabbly.com

Pabbly Support — Reply ·

Just following up one last time regarding this. Since we haven't heard back, we'll be closing this ticket for now. If you need further assistance, simply send an email to support@pabbly.com.

Thanks & Regards,
Arshil Ahmad
🌐 Pabbly.com

Back to all forum threads · Log in to reply