By default, WordPress automatically creates several copies of image uploads in different sizes. Additionally, WordPress themes and plugins can also create their own image sizes.
In this article, we’ll show you how to easily create additional image sizes in WordPress and use them on your website.
Why Create Additional Image Sizes in WordPress?
Normally, all popular WordPress themes and plugins handle image sizes very well. For instance, your WordPress theme may create additional sizes to use as thumbnails on archive pages.
However, sometimes these image sizes may not fit your own requirements. You may want to use a different image size in a child theme or a post grid layout.
You can do this by creating additional image sizes in WordPress and then calling these sizes whenever you need them.
That being said, let’s take a look at how to create additional image sizes in WordPress.
Registering Additional Image Sizes for your Theme
Most WordPress themes including all the top WordPress themes support post thumbnails (featured image) feature by default.
However, if you are creating a custom WordPress theme then you will need to add support for post thumbnails by adding the following code to your theme’s functions.php file.
add_theme_support( 'post-thumbnails' );
Once you enable the support for post thumbnails, you can now use the functionality of registering additional image sizes by using the function add_image_size().
The add_image_size function is used in the following format:
add_image_size( 'name-of-size', width, height, crop mode );
Example code can look like the following:
add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
Now if you notice, we have specified three different sorts of image sizes. Each has different modes such as hard crop, soft crop, and unlimited height.
Let’s cover each example and how you can use them in your own projects.
Read Origianl Post How to Add Custom Image Size in WordPress