WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/set post thumbnail size

This article is marked as in need of editing. You can help Codex by editing it.

Description

Set the default Featured Image (formerly Post Thumbnail) dimensions. To register additional image sizes for Featured Images use: add_image_size().

Note: To enable featured images, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.

Usage

 <?php set_post_thumbnail_size$width$height$crop ); ?> 

Parameters

$width
(int) (optional) The post thumbnail width in pixels.
Default: 0
$height
(int) (optional) The post thumbnail height in pixels.
Default: 0
$crop
(boolean or array) (optional) Crop the image or not. False - Soft proportional crop mode ; True - Hard crop mode. Alternately an array representing the crop position. e.g. array( 'left', 'top')
Default: false

Examples

Default Usage

To be used in the current theme's functions.php file.

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150 );

Note

This function will not resize your existing featured images. To regenerate existing images in the new size, use the Regenerate Thumbnails plugin.

Crop Mode

Set the default Post Thumbnail size by resizing the image proportionally (that is, without distorting it):

set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode

Set the default Post Thumbnail size by cropping the image (either from the sides, or from the top and bottom):

set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode

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

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

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

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

Change Log

Source File

set_post_thumbnail_size() is located in wp-includes/media.php.

Related

Post Thumbnails:

See also index of Function Reference and index of Template Tags.