Using WordPress ‘remove_image_size()’ PHP function

The remove_image_size() WordPress PHP function removes a previously registered image size.

Usage

remove_image_size( 'custom_image_size' );

Parameters

  • $name (string) – Required. The image size to remove.

More information

See WordPress Developer Resources: remove_image_size()

Examples

Remove extra image sizes

Remove all the image sizes except the default WordPress image sizes:

function remove_extra_image_sizes() {
    foreach ( get_intermediate_image_sizes() as $size ) {
        if ( !in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
            remove_image_size( $size );
        }
    }
}
add_action('init', 'remove_extra_image_sizes');

Remove an image size from a plugin

Remove an unwanted image size added by a plugin:

function wpdocs_remove_plugin_image_sizes() {
    remove_image_size( 'image-name' );
}
add_action('init', 'wpdocs_remove_plugin_image_sizes');

Replace an existing image size

Replace an existing image size with new dimensions:

function wpdocs_remove_then_add_image_sizes() {
    remove_image_size( 'image-name' );
    add_image_size( 'image-name', 200, 200, true );
}
add_action('init', 'wpdocs_remove_then_add_image_sizes');

Replace default image size

Replace the ‘medium’ WordPress default image size with new dimensions:

add_action( 'init', 'wpdocs_change_medium_image_size' );
function wpdocs_change_medium_image_size() {
    remove_image_size( 'medium' );
    add_image_size( 'medium', 300, 300, true );
}

Remove all default image sizes

Remove all the default WordPress image sizes:

update_option( 'thumbnail_size_h', 0 );
update_option( 'thumbnail_size_w', 0 );
update_option( 'medium_size_h', 0 );
update_option( 'medium_size_w', 0 );
update_option( 'large_size_h', 0 );
update_option( 'large_size_w', 0 );