Removes a new image size.
Parameters
$name
stringrequired- The image size to remove.
Source
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;
}
Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |
To remove all the image sizes keeping only the default WordPress image sizes –
Another common case is when your (parent) theme, or a plugin creates image sizes that you will never use.
Deregistering unwanted sizes will prevent WordPress from generating and storing images you won’t use.
This will save disk space, and associated costs.
Of course, it only affects future image uploads.
Plugins that “regenerate thumbnails” can be used to delete existing thumbnails that are not currently registered, while creating any missing sizes.
—
The article mentions that you cannot use this function on reserved image size names.
However there are a few work arounds:
Example
In a theme’s functions.php file:
You could combine this with the add_image_size function in your theme.
To replace any of the default image sizes like ‘medium’, ‘large’, etc you must remove first and then add with new attributes.