remove_image_size( string $name )

Remove a new image size.


Description Description


Parameters Parameters

$name

(string) (Required) The image size to remove.


Top ↑

Return Return

(bool) True if the image size was successfully removed, false on failure.


Top ↑

Source Source

File: wp-includes/media.php

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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Nikhil Chavan

    To remove all the image sizes keeping only 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');
  2. Skip to note 2 content
    Contributed by Codex

    Example

    In a theme’s functions.php file:

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

    You could combine this with the add_image_size function in your theme.

    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');
    
  3. Skip to note 3 content
    Contributed by akkis

    To replace any of the default image sizes like ‘medium’, ‘large’, etc you must remove first and then add with new attributes.

    /**
     * Add crop attribute to 'medium' WordPress default image size
     */
    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 );
    }
    

You must log in before being able to contribute a note or feedback.