What is the difference between set_post_thumbnail_size and add_image_size? Is set_post_thumbnail_size for all images, and add_image_size for sizing images individually?
When an image is uploaded in WordPress, it is saved in its original size, and also in some resized copies in different sizes, in this way became easy use different size of the same image for different purposes.
By default, WordPress, create 3 copies in 3 different size:
The size in pixel for these 3 sizes can be setted in WordPress dashboard, under the menu
Now, the function
All these functions accept a parameter
These two functions get (the first) and echo (the second) the image that is setted as "Featured Image" for a post.
What is returned (or echoed) by these functions is a full
so, which is the size used?
This is not one of the 3 default sizes, in fact, it is the 4th standard size (the 5th considering
is a shortcut for
If you haven't called
Register custom image sizes, can be very helpful when designing a theme, but it's important not abuse: every uploaded image is copied and resized for all the sizes registered, so, register a lot of sizes will heavily slow down the image uploading process.
Be aware that when WordPress creates scaled copies of an image, never enlarge it, but only make smaller copies: e.g. if the original image is 400x500 px, and the 'medium' image size is 800x600px, medium size and larger are not created.
So register an image size never gives the security that an image file for every size registerd actually exists in WordPress content folder. Even because registered image sizes easily change: changing setting, switching theme, ecc..
When an image size change, for every reason, the change has effect on the images uploaded after that change, images uploaded before don't change dimensions and are not rescaled and resaved.
If one needs to rely on specific image sizes after some images are already uploaded (e.g. after changing theme) then the plugin Regenerate image thumbnail will be life saver.