0

We are trying to change the crop style of the thumbnails attached to the posts on our website. This is the code we have used to declare a new image-size:

<?php

/** --- Thumbnails configuration **/

function add_custom_sizes() {
    add_theme_support('post-thumbnails', array('post', 'page', 'custom-post-type-name'));

    // Featured size 
    add_image_size( 'featured-big', 400, 400, true ); // width, height, crop
}

add_action('after_setup_theme','add_custom_sizes');

?>

We then call this image-size while printing out one of our thumbnails:

<?php 
    the_post_thumbnail( 'featured-big' );
?>

However the thumbnail doesn't seem to be cropped correctly. The parameter true in the add_theme_support function is supposed to 'Hard Crop' the image, however the image is 'Soft' cropped, incorrectly.

Any clues?

3

Image sizes and cropping settings do not apply retroactively: images that were present on your site before you made this change are not affected.

Your new settings will only apply to images you upload afterwards, because image are cropped at the time of uploading.

You can either try to upload a new image, or you can trigger the re-cropping of previously uploaded images to apply your new settings with the very handy Regenerate thumbnails plugin.

  • Thank you for your reply. I understand now, however I can't now understand the function of <?php the_post_thumbnail( 'featured-big' ); ?> I've different type of custom size, an example in my single page I'd like to have the featured-big, but in the content.php page, I'd like to have the featured-small size, both have the cropped parameter to TRUE. If the images will be cropped in the moment you're uploading them, it means that WordPress will not apply the custom size forcing them the crop I wanted. Is it my logic wrong? Thank you for any help – valentina.a87 Feb 12 '18 at 9:50
  • There might be a misunderstanding at some point. WordPress generates several thumbnails (one for each registered and custom sizes) based on the size and crop parameter. It does that for each image at the moment it is added to the media library (or when you use the regenerate thumbnails plugin). Once this is done, all different generated thumbnails are kept in the uploads folder, ready to be served when you call the a function such as the_post_thumbnail( $size );. If you register new sizes in your theme, you need to use the Regenerate Thumbnails plugin to crop new thumbnails of old image. – Iceable Feb 12 '18 at 10:59
  • Ok, now everything is clear and working perfectly! Thank you very much for your patience! Have a nice day! :) – valentina.a87 Feb 12 '18 at 16:31

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.