Get medium image size in WordPress

May 27, 2008

in Code, 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.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Twitter

Related posts:

  1. Admin Drop Down Menu plugin does not break WordPress 2.5 Image Uploader [updated]
  2. Get Adjacent Images – More WordPress Functions
  3. Nofollow SEO for your WordPress Functions
  4. How to View All (or more) Posts at once in WordPress Administration
  5. How to tell if your WordPress Plugin or Widget is Activated in WordPress

{ 5 comments… read them below or add one }

kristarella November 18, 2008 at 5:22 pm

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

Reply

yakuter April 5, 2009 at 5:50 am

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…

Reply

Karl September 16, 2009 at 10:11 am

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

Reply

Jermaine Maree October 10, 2009 at 5:10 pm

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.

Reply

Zack Katz October 12, 2009 at 3:31 pm

Glad you found it helpful!

Reply

Leave a Comment

Previous post:

Next post: