In WordPress we can set our own custom image sizes image sizes with function add_image_size().

Table of Content

Build In Image Sizes Build In Image Sizes

Before see how to add them, Lets see what type of in build image sizes WordPress provide us.

By default WordPress have 3 image sizes:

  • Thumbnail (150×150)
  • Medium (300×300)
  • Large (1024×1024)
  • Full (Original Image Size)

You can change these default image sizes from Settings > Media.

Default image sizes.

Additionally, If yo u want define your own image sizes then you can simply do it with function add_image_size().

Add Own Image Sizes Add Own Image Sizes

Below is the code snippet to add additional image sizes.

Just copy and paste below code into your child themes functions.php file.

/**
 * Add image sizes
 * 
 * @todo Change the `prefix_` and with your own unique prefix.
 * 
 * @since 1.0.0
 */
if( ! function_exists( 'prefix_add_image_sizes' ) ) :
	function prefix_add_image_sizes() {

		// Crate image with 400xauto.
		add_image_size( 'image-size-400', '400' );

		// Create image size 600x800. Soft Crop.
		add_image_size( 'image-size-600-800', '600', '800' );

		// Crate image size 800x900. Hard Crop.
		// Hard crop does not maintain the image ratio.
		add_image_size( 'image-size-600-800-hard-crop', '800', '900', true );

		// Crate image size 600x900. Hard Crop.
		// Hard crop does not maintain the image ratio.
		// It start crouping image from horizontally `left` and vertically from `top`.
		add_image_size( 'image-size-600-900-left-top', '600', '900', array( 'left', 'top' ) );

		// Crate image size 600x1000. Hard Crop.
		// Hard crop does not maintain the image ratio.
		// It start crouping image from horizontally `center` and vertically from `center`.
		add_image_size( 'image-size-600-1000-center-center', '600', '1000', array( 'center' ), 'center' );
   }
   add_action( 'init', 'prefix_add_image_sizes' );
endif;

Leave a Reply

Your email address will not be published. Required fields are marked *