I want know width and height from (images) Logo and Crest, current I use standard PHP function getimagesize in my theme

 *  Get dimensions for image
if (!function_exists('get_image_dimensions')) {
    function get_image_dimensions($url)
        $size = getimagesize($url); 
        $width = $size[0];
        $height = $size[1];

        return array('width' => $width, 'height' => $height);

Exist native function for it ?

  • Your function looks fine. Since PHP provides getimagesize(), there's no need for a WordPress function to duplicate it.
    – Pat J
    Mar 31 at 17:52
  • @PatJ but with this function site loading to be little bit slow in according with Lighthouse
    – salsan
    Mar 31 at 18:01
  • If there was a WP function to do this, it would almost certainly use getimagesize() as well. If getimagesize() is slowing down your site, you might consider stashing its results in an option so you only need to run it once (assuming that your logo and crest don't change).
    – Pat J
    Mar 31 at 18:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.