How to Add Additional Image Sizes in WordPress

Home » Snippets » How to Add Additional Image Sizes in WordPress

Created with:



Creator: WPTurbo Team

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project

Do you want to take more control over the way your images are displayed on your WordPress site? One simple way of achieving this is to create additional image sizes. While WordPress has a few default sizes available to use, sometimes they might not fit the exact dimensions you’re looking for. In this article, we will guide you through the process of adding new image sizes to your WordPress site, step by step.

					function wpturbo_additional_image_sizes() {
    add_image_size( 'custom-size', 800, 600, true ); // width, height, crop
    add_image_size( 'another-size', 1200, 800, array( 'left', 'top' ) ); // width, height, array(x_crop_position, y_crop_position)
add_action( 'after_setup_theme', 'wpturbo_additional_image_sizes' );

The code snippet above is used to add additional image sizes to your WordPress website. This feature can be extremely useful if your website needs to display images in different sizes and dimensions, as it allows you to offer a range of options to your users depending on their needs.

The add_image_size function is used to define new sizes for your images. The first parameter is the name of the new size, which you can call anything you like. The second and third parameters define the width and height of the image, respectively. The fourth parameter, true or an array of crop position, determines whether the image should be cropped or resized proportionally. A value of true will crop the image to exactly fit the specified dimensions, while an array of crop positions (for example, array( 'left', 'top' ), as seen in the second image size) will resize the image and then crop it from the specified positions.

Once you have defined your new image sizes using add_image_size(), you need to hook this function into the WordPress action after_setup_theme. This ensures that the new image sizes are registered and available for use within your theme.

Overall, adding additional image sizes can make your WordPress website much more versatile, as it allows you to offer a range of options to your users depending on their needs.

Register an account to save your snippets or go Pro to get more features.