remove_image_size( string $name ): bool
Removes a new image size.
Parameters
-
$name
string Required -
The image size to remove.
Return
bool True if the image size was successfully removed, false on failure.
More Information
- Useful when a plugin has registered an image size and you want to use the same image name in your theme but with a different size.
- Cannot be used on reserved image size names.
Source
File: wp-includes/media.php
.
View all references
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. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
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.
Top ↑
Feedback
But the docs say: “Cannot be used on reserved image size names.” https://developer.wordpress.org/reference/functions/remove_image_size/ — By nicohood —