Skip to content

Instantly share code, notes, and snippets.

@shanejones
Last active March 20, 2019 21:04
Show Gist options
  • Save shanejones/e3af6e5ce487b0d805536a2d8e8362d1 to your computer and use it in GitHub Desktop.
Save shanejones/e3af6e5ce487b0d805536a2d8e8362d1 to your computer and use it in GitHub Desktop.
/**
* 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