I want a thumbnail of the featured image of the posts as a URL. So I’m using the following code to get a smaller size of the featured image.

$post[$i]['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($post[$i]['id'], 'thumbnail'));

However all the time it returns the full size image, I even tried,

 $post[$i]['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($post[$i]['id'], array(120,140)));

But still it returns the large image. How can I fix this?

3 Answers
3

Hey First add this line into your function.php file

add_image_size( 'custom-size', 120, 140 );

Then call custom-size like this

<?php $thumb_id = get_post_thumbnail_id( $id );
                if ( '' != $thumb_id ) {
                    $thumb_url  = wp_get_attachment_image_src( $thumb_id, 'custom-size', true );
                    $image      = $thumb_url[0];
                }?>
            <img src="https://wordpress.stackexchange.com/questions/172703/<?php echo $image;?>">

I think it work fine

Leave a Reply

Your email address will not be published. Required fields are marked *