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.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.