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 as some resized copies in different sizes. In this way it becomes easy to use different sizes, of the same image, for different purposes.
By default, WordPress creates 3 copies in 3 different sizes:
The size in pixels for these 3 sizes can be set in the 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 set 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 is considered
is a shortcut for
If you haven't called
Registering custom image sizes can be very helpful when designing a theme, but it's important not to abuse: every uploaded image is copied and resized for all the sizes registered, so registering a lot of sizes will heavily slow down the image uploading process.
Be aware that when WordPress creates scaled copies of an image, it never enlarges it, but only makes smaller copies: e.g. if the original image is 400x500px, and the 'medium' image size is 800x600px, medium size and larger are not created.
So registering an image size never gives the security that an image file for every size registered actually exists in the WordPress content folder. Even because registered image sizes easily change: changing settings, switching themes, etc.
When an image size changes, for any reason, the change has an 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 themes), then the plugin Regenerate Thumbnails will be a life saver.