set_post_thumbnail_size()WP 2.9.0

Registers an image size for the post thumbnail.

No Hooks.

Return

null. Nothing.

Usage

set_post_thumbnail_size( $width, $height, $crop );
$width(int)
Image width in pixels.
$height(int)
Image height in pixels.
$crop(true|false|array)
Whether to crop images to specified width and height or resize. An array can specify positioning of the crop area.
Default: false

Examples

0

#1 Basic example

Define the use of thumbnails in the template and specify the size of the post thumbnail:

if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 150, 150 );
}
0

#2 Cropping

Resize proportionally: Set the default thumbnail size to 50x50 pixels. The image will be resized by the smallest side. On the larger side, the edges will be cropped.

set_post_thumbnail_size( 50, 50 ); // shrink the picture

Cropping: set the default thumbnail size to 50x50 pixels. The image will be cropped: the central part of the image will be taken with a size of 50x50 pixels:

set_post_thumbnail_size( 50, 50, true ); // cropping

Cropping: Set the default Post Thumbnail size by cropping the image from top left:

// 50 pixels wide by 50 pixels tall, crop from the top left corner
set_post_thumbnail_size( 50, 50, array( 'top', 'left')  ); 

Cropping: Set the default Post Thumbnail size by cropping the image from the center:

// 50 pixels wide by 50 pixels tall, crop from the center
set_post_thumbnail_size( 50, 50, array( 'center', 'center')  ); 

See add_image_size() for more information about cropping.

Note: This function will not resize your existing images. To regenerate existing images in the new sizes, use the Regenerate Thumbnails plugin.

Notes

Changelog

Since 2.9.0 Introduced.

set_post_thumbnail_size() code WP 6.1.1

function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
	add_image_size( 'post-thumbnail', $width, $height, $crop );
}