I am using the Manual Image Crop plugin to set thumbnails for images. I am not using any images as 'featured images' however.

I have a number of thumbnails saved to each image. If I use wp_get_attachment_link(id, 'medium'); then I get the desired 'medium' thumbnail returned but as whole html block output, including '' tags, size etc etc.

I just want the URL of this specific thumbnail (or the img tags 'src' attribute). Is there a built in wordpress function for this or will I have to use PHP regex or something?


Have a look at wp_get_attachment_image_src

$attachment_id = 8; // attachment ID

$image_attributes = wp_get_attachment_image_src( $attachment_id, 'medium' ); // returns an array
if( $image_attributes ) {
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>

Source: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src#Default_Usage

  • this only seems to get the 150x150 thumbnail src – myol Nov 25 '14 at 17:38
  • I don't want to be rude but if you hadn't just copied the code but would have had just a short little look at the links provided you would have seen that there is a second parameter for the size. Anyway - I updated the code. – kraftner Nov 25 '14 at 19:40
  • I do apologise, I must have read an incorrect browser tab half asleep. This is the exact function I was looking for, thank you. – myol Nov 26 '14 at 9:25

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.