0

I'm using the following code to add a featured image to my rss feed in wordpress.

add_action( 'rss2_item', 'add_post_featured_image_as_rss_item_enclosure' );

function add_post_featured_image_as_rss_item_enclosure() {
if ( ! has_post_thumbnail() )
    return;

$thumbnail_size = apply_filters( 'rss_enclosure_image_size', 'thumbnail' );
$thumbnail_id = get_post_thumbnail_id( get_the_ID() );
$thumbnail = image_get_intermediate_size( $thumbnail_id, $thumbnail_size );

if ( empty( $thumbnail ) )
    return;

$upload_dir = wp_upload_dir();

 printf( 
    '<enclosure url="%s" length="%s" type="%s" />',
    $thumbnail['url'], 
    filesize( path_join( $upload_dir['basedir'], $thumbnail['path'] ) ), 
    get_post_mime_type( $thumbnail_id ) 
 );
}

But the plguin above is outputting a really small image 150x150. I tried changing the thumbnail size to full or large, but it won't work. Is there any way to add a url to the full featured image size in the enclosure field below?

Thanks in advance

2 Answers 2

1

You can use the get_post_thumbnail_id to get the ID of the thumbnail, then with the function wp_get_attachment_image_src you can get the image of the size you want, including full size, using the second paramenter.

$thumb_id = get_post_thumbnail_id(get_the_ID());    
$thumb_data = wp_get_attachment_image_src( $thumb_id, 'full');

Now in $thumb_data you have a nice array, or false if there's no image.

The array has this structure:

[0] => url

[1] => width

[2] => height

[3] => boolean: true if $url is a resized image, false if it is the original.

0

On the line below, you just need to change "thumbnail" at the end to "large". That should do the trick

$thumbnail_size = apply_filters( 'rss_enclosure_image_size', 'thumbnail' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.