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 purpose.
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
Every size registered can be retrieved using its name, in some WordPress function, e.g.
All these functions accept a parameter
In addition to the functions mentioned above, there are other 2 functions that make use of image sizes:
These 2 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 this functions is a full
If you haven't called
Register custom image sizes, can be very helpful for design a theme, but it's important not abuse: every image is uploaded is copied and resized for all the sizes registered, so, register a lot of sizes will heavily slow down the image uploading process.
A note. Be aware that when WordPress create the 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 800x600 px, 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 image size registered 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 need 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.