As I already used the featured image for something else, I want to add another image and display it in one of the sizes defined in my functions.php with add_image_size().

I know how to do that with a featured image : I just have to use the_post_thumbnail() function and indicate the size I want in the parameters. But what about a post image ?

  • Are you trying to display this image programmatically (i.e. directly in a template file), or as part of the Post Content? Jul 12, 2011 at 20:18

4 Answers 4


Try using wp_get_attachment_image() (Codex ref)?

echo wp_get_attachment_image( $attachmentid, $imagesize );

Where $attachmentid is the attachment ID, and $imagesize is the name of the image size in the add_image_size() call.


For a custom-field stored image SRC URL, I'm not finding any way to make use of intermediate image sizes defined via add_image_size() (or even the default image sizes). Pretty much all of the related functions eventually require an attachment ID.

  • I'm stupid, it's not a post image that I want to display but an image whose URL has been added in a custom field !
    – Mike
    Jul 12, 2011 at 22:27
  • Any particular reason you can't use the Media Manager for post-attached images, rather than custom fields? But, you're storing an IMG SRC as a custom field? Let me update my answer... Jul 12, 2011 at 23:44
  • well I don't want the image to appear in the post content, I just use this image to feature the post (and a small piece of its textual content only) on the front page. I use its featured image to feature it elsewhere in the front page, for a different reason (that doesn't matter much here) So there is no solution to my problem ?
    – Mike
    Jul 13, 2011 at 8:05
  • As far as I can tell, no. You can use any arbitrarily sized image in a custom field, and you can display it in your template, but I can't find any way to tie the size of a custom-field image to an add_image_size() image size. Jul 13, 2011 at 11:20
  • Gosh, I'll have to find another solution then. Thanks anyway!
    – Mike
    Jul 14, 2011 at 11:14

Yes, more or less. The $name parameter of add_image_size with can be called like this,

the_post_thumbnail( 'your_add_image_size_name' );
  • He said he's already used the featured image (i.e. the post thumbnail) for another purpose, so I presume this need would be for any arbitrary image other than the featured image. Jul 12, 2011 at 20:21

Within you functions.php, first define your custom thumbnail image:

add_image_size( 'custom_thumbnail', 300, 200, true );

Then use the following code to retrieve this thumbnail size:

$image_data = wp_get_attachment_image_src($attachment->ID , 'custom_thumbnail');

There is no post image, maybe you mean the post featured image? If so you can get the attachment id using this:

$thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', TRUE);

then use

$image_data = wp_get_attachment_image_src($thumbnail_id , 'custom_thumbnail');

Or get all post images:

$argv = array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order' ); $attachments = get_children($argv);


You need to think a bit different to solve this one, at the moment I see two different approaches to the problem.

You can use some css to resize the image, just assign a class to the image based on your add_image_size preferences and set some css rules to give the desired size, not a real resize, but sometimes it's enough.

Or you can use some third party script like tinythumb to generate a real 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.