If you’ve ever wanted to add your own custom image sizes to your WordPress theme, you’re in luck! In this article, we’ll show you how to add new image sizes to your WordPress theme using the add_image_size function.

First, you’ll need to open up your theme’s functions.php file and add the following code:

function add_custom_image_sizes() {
    add_image_size( 'name', width, height, crop );
}
add_action( 'after_setup_theme',  'add_custom_image_sizes' );

To use the add_image_size function, you need to hook into the after_setup_theme action.

Replace ‘name’ with the name you want to give your image size, width with the width you want your image to be, height with the height you want your image to be, and crop with either true or false. If you set crop to true, your image will be cropped to the exact width and height you specified. If you set crop to false, your image will be resized to fit within the width and height you specified.

For example, if you wanted to add a custom image size called ‘small-square-thumbnail’ that was 150×150 pixels, you would use the following code:

function add_custom_image_sizes() {
    add_image_size( 'small-square-thumbnail', 150, 150 );
}
add_action( 'after_setup_theme',  'add_custom_image_sizes' );

You can add as many size variations as you want:

function add_custom_image_sizes() {
    add_image_size( 'thumbnail-big', 720, 400 );
    add_image_size( 'thumbnail-bigger', 1600, 800 );
}
add_action( 'after_setup_theme',  'add_custom_image_sizes' );

Pin It on Pinterest

Share This