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 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

1 Answer 1

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

 
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.