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

User:Esmi/add image size()

Registers a new post_thumbnail size


add_image_size( $name, $width = 0, $height = 0, $crop = FALSE)
The custom image name (eg: index_thumb)
The thumb width in pixels
The thumb height in pixels
false:Soft, proportional crop mode (default)
true: Hard crop mode


A theme's functions.php file.

if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) { 
	add_image_size( 'cat-thumb', 200, 200 );
	add_image_size( 'search-thumb', 220, 180, true );

Child Theme Usage

Simply copy & paste the following line to your child themes functions file and modify the values for the width and height.

add_image_size( 'name-your-image', 220, 180, true );

Using the New Image Sizes

Within a theme's template files.

<?php if ( has_post_thumbnail()) the_post_thumbnail('cat-thumb'); ?>

Defined in wp-includes/media.php