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?
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?
Share Improve this question asked Nov 25, 2014 at 12:57 myolmyol 7962 gold badges13 silver badges37 bronze badges2 Answers
Reset to default 2Have a look at wp_get_attachment_image_src
<?php
$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/Function_Reference/wp_get_attachment_image_src#Default_Usage
if you have the $id = 7
for example
and you have $size = ...;
choose the size you want
use wp_get_attachment_image_url($id, $size)