set_post_thumbnail_size( int $width, int $height, bool|array $crop = false )

Registers an image size for the post thumbnail.


Description

Top ↑

See also


Top ↑

Parameters

$width int Required
Image width in pixels.
$height int Required
Image height in pixels.
$crop bool|array Optional
Image cropping behavior. If false, the image will be scaled (default).
If true, image will be cropped to the specified dimensions using center positions.
If an array, the image will be cropped using the array to specify the crop location:
  • string
    The x crop position. Accepts 'left' 'center', or 'right'.
  • 1 string
    The y crop position. Accepts 'top', 'center', or 'bottom'.

Default: false


Top ↑

More Information

  • To register additional image sizes for Featured Images use: add_image_size() .
  • To enable featured images, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.
  • This function will not resize your existing featured images. To regenerate existing images in the new size, use the Regenerate Thumbnails plugin.

Top ↑

Source

File: wp-includes/media.php. View all references

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


Top ↑

Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Codex

    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( 'top', 'left')  ); // 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

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

  2. Skip to note 3 content
    Contributed by Gabor Lippert

    I guess this just stopped working in the new Gutenberg editor environment. ¯\_(ツ)_/¯

    At least with the below, totally standard usage, the function doesn’t have any effect on the way a post thumbnail gets displayed on a post edit screen.

    function wpdocs_mac_setup_theme() {
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 280, 153, false );
    }
    add_action( 'after_setup_theme', 'wpdocs_mac_setup_theme' );

You must log in before being able to contribute a note or feedback.