Last active
March 20, 2019 21:04
-
-
Save shanejones/e3af6e5ce487b0d805536a2d8e8362d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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