micalexander
5/29/2014 - 8:08 PM

wordpress:\mask:snippet

wordpress:\mask:snippet

class Mask {
    
    // get image and meta including title, alt, caption, and description
    function get_image( $size = null, $post_id = null )
    {
        $img = wp_prepare_attachment_for_js(get_post_thumbnail_id($post_id));

        if ($size != null)
        {
            if (!array_key_exists($size, $img['sizes']))
            {
                return $img['url'];
            }
            else
            {
                return $img['sizes'][$size]['url'];
            }
        }
        else
        {
            return $img;
        }
    }
}