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?

2 Answers
2

Have 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="https://wordpress.stackexchange.com/questions/169475/<?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

Tags:

Leave a Reply

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