Image Size

The default image dimensions provided by WordPress are standard image sizes, but themes may require images of different sizes depending on the layout requirements.

We added the below custom image sizes in the Sam Martin theme.

Image Size NameImage WidthImage HeightCropped
sam-martin-post-thumbnails500333false
sam-martin-banner-image1920490false
sam-martin-post-images1170370false
sam-martin-portfolio-slider900900true

Despite this, users sometimes require a different image size as per the requirement. You must add custom image size(s) if you have any such requirements. To add your custom image size(s), you’ll need to follow the two steps below:

  • Step 1. Register Image Sizes
  • Step 2. Regenerate Thumbnails

Register Image Sizes

Hook your custom function to the sam_martin_image_sizes filter to add a new image size. Here below is the sample code, which you can add to the child theme’s functions.php.

function sam_martin_child_image_sizes( $image_sizes ) {
	// Add your image sizes.
	$image_sizes['sam_martin_custom_200'] = array(
		'name'  => 'sam_martin_custom_200',
		'width' => 200,
		'height'=> 200,
		'crop'  => true,
		'label' => esc_html__( 'Sam Martin Custom 200', 'sam-martin-child' ),
	);
	return $image_sizes;
}
add_filter( 'sam_martin_image_sizes', 'sam_martin_child_image_sizes' );

Please refer to the below documents for detailed information about the image size and names and labels of the image sizes.

Regenerate Thumbnails

If you add new image sizes to your existing site, you must regenerate the thumbnails. This is necessary because WordPress will only resize images that have been uploaded after registering the new image size.

Therefore, any image (added/uploaded before registration of the new image size) will not have any new size. So, you need to regenerate the new image size for the old images.

To regenerate the image, you can use the below plugins. For details about settings and usage, please refer to the instructions provided on the plugins page.

  1. Regenerate Thumbnails
  2. AJAX Thumbnail Rebuild

The newly added image size and size names will appear in different sections of the site.

Important Note: If you want to manage/control the above image sizes, you can hook your custom function to the sam_martin_image_sizes filter hook, by which you can either change the image size dimension/parameters or add/delete any predefined image size. While deleting any predefined image size, ensure that these defined image sizes are used in various sections on the site.

Suggest Edit