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?


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



(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 ).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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