remove_image_size & has_image_size image functions

These new image functions enable you to remove custom image sizes by name conditionally using a custom function and check if your theme has the custom image size by name included.

The 2 New image functions are:

  1. remove_image_size(‘$name’);
  2. has_image_size(‘$name’);

Remove Image Size

add_action('init', 'wpsites_remove_then_add_image_sizes');
function wpsites_remove_then_add_image_sizes() {
	remove_image_size('$name');
	add_image_size( '$name', 300, 150, array( 'left', 'top' ) );
}

Has Image Size

add_action('after_setup_theme', 'wpsites_remove_image_size');
function wpsites_remove_image_size() {
	if(has_image_size('$name')) {
	remove_image_size('$name');
	}
}

Usage

Replace $name with the name of your existing image size or new size

The custom functions would generally go in your child themes functions.php file however you could use them in other files.

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.