remove_image_size()WP 3.9.0

Removes a previously registered image size by it name. The new image size is registered with add_image_size().

It can be useful, for example, when the theme registers a new size, and you need to change this size.

This function uses $_wp_additional_image_sizes variable which contains the new registered image sizes.

No Hooks.

Return

true|false. True if the image size was successfully removed, false on failure.

Usage

remove_image_size( $name );
$name(string) (required)
The image size name you want to delete. The name should be the same as was used in add_image_size() function.

Examples

0

#1 Remove an image size

Suppose that we use a plugin which registers a new image size and we want to remove it:

add_action( 'after_setup_theme', 'remove_plugin_image_sizes' );
function remove_plugin_image_sizes() {
	remove_image_size('image-name');
}
0

#2 Change the sizes of thumbnail

In this example, we redefine the image size with the same name but another thumbnail sizes:

add_action( 'after_setup_theme', 'remove_then_add_image_sizes' );
function remove_then_add_image_sizes(){
	add_image_size( 'image-name', 200, 200, true );
}

Notes

  • Global. Array. $_wp_additional_image_sizes

Changelog

Since 3.9.0 Introduced.

remove_image_size() code WP 6.5.2

function remove_image_size( $name ) {
	global $_wp_additional_image_sizes;

	if ( isset( $_wp_additional_image_sizes[ $name ] ) ) {
		unset( $_wp_additional_image_sizes[ $name ] );
		return true;
	}

	return false;
}