Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have code that looks like this:

$post_thumbnail = the_post_thumbnail( array ( $w, $h ) );

I want to know what I'm doing wrong. When I pass in values for width and height, Wordpress returns an image with the correct hight but with the incorrect width. Is it possible for me to get the exact image specified?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Always start with the Codex. According to the function reference for the_post_thumbnail():

Parameters

$size

(string/array) (Optional) Image size. Either a string keyword (thumbnail, medium, large, full), or any custom size keyword defined by add_image_size(), or a 2-item array representing width and height in pixels, e.g. array(32,32).

Default: 'post-thumbnail', which theme sets using set_post_thumbnail_size.

PLEASE NOTE: The crop does not work in Wp 3.0+. All that is needed for WP 3.0+ is the call for the thumbnail to post. Then proceed to media in the dashboard and set your thumbnail to crop to the size you wish to use.

You need to create your custom image size, via add_image_size( $name, $w, $h, $crop ), and then call the_post_thumbnail( $name ).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.