Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Function to check weather or not an image sizes exists in the thumbnail library for a specific attachment id
*
* @param $attachment_id - the id of any image in the se
* @param $image_size_name - the name from add_image_size()
*
* @return bool
*/
function check_image_size( $attachment_id, $image_size_name ){
$image_info = wp_get_attachment_metadata( $attachment_id );
$sizes = $image_info['sizes'];
if( array_key_exists($image_size_name, $sizes) ){
return true;
} else {
return false;
}
}
/** Usage */
$image_exists = check_image_size( $image_id, 'thumbnail' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.