markzzz
markzzz

Reputation: 48015

How to enable image on RSS generated by wordpress?

I'd like to add the tag on rss generated by Wordpress (http://www.myblog.com/rss) that take the first attached image for each post.

How can I do it?

Tried to download/install these :

http://wordpress.org/extend/plugins/wp-rss-images/

http://wordpress.org/extend/plugins/rss-image-feed/

but nothing change to the generated RSS!

EDIT

Tried this solution, after some suggestions :

add_action('rss2_item', 'add_images_to_rss');
function add_images_to_rss() {  
    ?>
    <my_meta_value><?php echo "prova" ?></my_meta_value>
    <?php
}

still I don't see any changes in the RSS source...

Upvotes: 0

Views: 845

Answers (1)

janw
janw

Reputation: 6662

Add this to your functions.php

// add the <image> to the rss and rss2 feed
function SO13586900_add_image_to_rss() {
    $thumb_id = get_post_thumbnail_id( get_the_ID() );
    if ( ! empty( $thumb_id ) ) {
        echo '<image>' . wp_get_attachment_url( $thumb_id ) . '</image>';
    }
}
add_action('rss2_item', 'SO13586900_add_image_to_rss');
add_action('rss_item', 'SO13586900_add_image_to_rss');

Tested and works

Upvotes: 2

Related Questions