Home » Functions » add_image_size

If you’re working on a WordPress website, you’ve probably had to deal with images at some point. Whether it’s uploading them to a post or page or using them in a theme, images are an important part of any website. However, images can also be a source of frustration if they’re not properly optimized. This is where the add_image_size() function comes in.

The add_image_size() function is a built-in WordPress function that allows you to define custom image sizes for your website. By using this function, you can create custom image sizes that fit specific areas of your website, such as a custom thumbnail size for your blog posts or a larger size for your featured images.

Using the add_image_size() function is relatively simple. You’ll need to specify a unique name for your new image size, as well as the width and height of your desired dimensions. You can also set a crop parameter, which tells WordPress whether to crop the image to fit the specified dimensions or to resize the image to fit within those dimensions.

Here’s an example code that creates a custom image size with a width of 600 pixels and a height of 400 pixels, and crops the image to fit those dimensions:

add_image_size( 'custom-size', 600, 400, true );

Once you’ve defined your custom image size, it will be available in the WordPress media uploader, and you can use it in your theme by calling the size name in your image code.

Overall, the add_image_size() function is a powerful tool for optimizing your images on your WordPress website, and it can help ensure that your images are the right size and dimensions for your website’s needs.

Learn More on

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