Get medium image size in WordPress

This is for everyone who’s been trying to find out how to get the medium image size of a post attachment in WordPress:

You’ve got to send the function the ID you’re trying to get the medium images for.

$medium = wp_get_attachment_image_src($picture->ID, 'medium', false);
$med_url = $medium[0];
$med_width = $medium[1];
$med_height = $medium[2];

There are a lot more things you can find out by analyzing wp-includes/gallery.php.

Author: Zack Katz

Zack Katz is the creator of GravityView and the President of Katz Web Services. He lives in Denver with his wife and cute beast of a cat.

8 thoughts on “Get medium image size in WordPress”

  1. Thank you so much. This is really helpful.

    Additionally I use the customfield for my image name and to find the image ID use an SQL like

    $imageID=”SELECT * FROM `wp_posts` WHERE guid=’$image[0]'”;

    Then I use your code and life is good ­čÖé

    Thanks again…

  2. Hello,
    This is very useful, thanks!

    I was wondering if it’s possible to get medium size of an attachement if I don’t know $picture->ID, but rather url of attachment.


  3. Right on, thanks for this one.┬á Very helpful and smart to reduce the image file size instead of just hard-coding the large image’s width to be the smaller dimension.

Leave a Reply

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