Skip to content

Instantly share code, notes, and snippets.

@shanejones
Last active March 20, 2019 21:04

Revisions

  1. Shane Jones renamed this gist Mar 20, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Shane Jones created this gist Mar 20, 2019.
    25 changes: 25 additions & 0 deletions WP Check Image Size
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /**
    * 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' );