Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/has image size

This page redirects to an external site: https://developer.wordpress.org/reference/functions/has_image_size/

Description

Checks if an image size name has been registered using add_image_size(). This is a boolean function, meaning it returns either TRUE or FALSE.

Since it only checks for image sizes that are registered via add_image_size() function, core image sizes namely small, medium, medium_large and large will not be considered. Hence, checking for a core image size using has_image_size() will always return FALSE.

Usage

<?php has_image_size($name); ?>

Return Values

(boolean) 
true on success, false on failure.

Parameters

$name
(string) (required) The registered image size name to check for.
Default: None

Examples

In a theme's functions.php file combined with remove_image_size():

add_action('after_setup_theme', 'remove_registered_image_size');

function remove_registered_image_size() {
	if(has_image_size('image-name')) {
		remove_image_size('image-name');
	}
}


Changelog

Source File

has_image_size() is located in wp-includes/media.php.

Related

Post Thumbnails:

See also index of Function Reference and index of Template Tags.