WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following line of code to create a new image size:

add_image_size('single-post-image', 600, 370, true);

However, this line of code does not guarantee that, the image will be of 600X370 size, it guarantees that, this is the maximum size, and smaller images will not be resized.

In my case however, I need a guarantee that, every image I use will be of 600X370.

share|improve this question

The answer to you question can be found here: http://stackoverflow.com/questions/10722466/how-do-i-force-wordpress-thumbnails-to-stretch-to-fit-if-uploaded-image-has-smal

Add this code to your functions.php to strip the hardcoded width and height of the images that are integrated inside Wordpress:

add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );

function remove_thumbnail_dimensions( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;

and you will need to add the following line to your active theme's style.css to stretch the image:

.attachment img {
    width: 100%; /* scale to width of container, or whatever you want */

Just make sure you are using the correct selector and width / height in your CSS.

share|improve this answer

Your Answer


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.