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.

Related posts:

  1. Admin Drop Down Menu plugin does not break WordPress 2.5 Image Uploader [updated]
  2. How to tell if your WordPress Plugin or Widget is Activated in WordPress
  3. Hierarchical Link Categories for WordPress
  4. WordPress.com finally updates to 2.5 — A review
  5. Nofollow SEO for your WordPress Functions

This entry was posted in Code, WordPress and tagged , , , . Bookmark the permalink.
  • http://www.kristarella.com kristarella

    Thank you! I wasn’t quite getting from the function to utilising the array output. I get it now!

  • http://www.yakuter.com yakuter

    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=’http://www.site.com/wp-content/uploads/$image[0]‘”;

    Then I use your code and life is good :)

    Thanks again…

  • Karl

    Thanks – I didn’t get why I just got “Array” printed on the page, now I understand.

  • http://wpbandit.com Jermaine Maree

    This information is priceless! Thanks so much for sharing. Was searching around quite a bit trying to figure out the best way to accomplish this.

    • http://www.katzwebservices.com Zack Katz

      Glad you found it helpful!

  • http://dashaluna.com Dasha

    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.

    Thanks.

  • http://www.facebook.com/anton.bielousov Anton Bielousov

    This is a boolshit. Everyone know this from WP documentation but it doesn’t return ‘medium’ size url.What this returns is a Full Size image URL + Medium size width and height this is useless for large enough lists of thumbnails like this one I have: http://www.bielousov.com/tag/toronto/ because the page becomes too heavy.

  • Matt Cassarino

    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.