0

I am trying to show thumbnail image as an attachment in the feed. So I use following code.

function add_images_to_rss($var) {
    global $post;
    if(has_post_thumbnail($post->ID)) {     
        $tid = get_post_thumbnail_id( $post->ID);
        //$thumb = wp_get_attachment_image_src($tid, 'large');      
        $thumb = wp_get_attachment_image_src($tid, '100x100');  
        $thumb_meta = wp_get_attachment_metadata($tid);
        $up = wp_upload_dir();
        print '<enclosure type="'.get_post_mime_type($tid).'" length="'.filesize($up['basedir'].'/'.$thumb_meta['file']).'" url="'.$thumb[0].'" />';
    }
}
add_action('rss2_item','add_images_to_rss'); 

But it shows larger size images as attachment. It suppose to show 100x100 size attachments only. What I am doing wrong ?

How can I show 100x100 image size attachemnts in that feed?

site is : http://www.supgower.com/feed/

1

You are using the size parameter of wp_get_attachment_image_src in a wrong format. This parameter can be:

  • A string: keyword of the image size; thumbnail, medium, large, full or any other custom size previously registered).
  • A 2-items array representing the width and height; for example, array( 100, 100 ).

So, you have to change this:

$thumb = wp_get_attachment_image_src($tid, '100x100'); 

With:

$thumb = wp_get_attachment_image_src( $tid, array(100,100) );

And this should also work for thumbnail size:

$thumb = wp_get_attachment_image_src( $tid, 'thumbnail' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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