-2

This question already has an answer here:

How to show file size of featured image in post on single.php?

For example: File size of featured image is: xx kb/Mb

I need size of featured "full" rezolution, also file size of "medium" resolution would be great?

Best regards.

marked as duplicate by kaiser Jul 1 '14 at 15:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Following function calculate file size, just you need change '/myfile/image.jpg' with your featured image variable.

   <?php 
    function file_size($url){ 
        $size = filesize($url); 
        if($size >= 1073741824){ 
            $fileSize = round($size/1024/1024/1024,1) . 'GB'; 
        }elseif($size >= 1048576){ 
            $fileSize = round($size/1024/1024,1) . 'MB'; 
        }elseif($size >= 1024){ 
            $fileSize = round($size/1024,1) . 'KB'; 
        }else{ 
            $fileSize = $size . ' bytes'; 
        } 
        return $fileSize; 
    }


    $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

   //echo file_size('/myfile/image.jpg');
     echo file_size($feat_image);  
    ?>

And check out WP Codex

  • 3
    Try size_format(). – fuxia Jul 1 '14 at 9:04
  • Thank you. Any idea how to replace '/myfile/image.jpg' with current post featured image? – Advanced SEO Jul 2 '14 at 9:34
  • I updated code. I didn't test it. – Erdal Bakkal Jul 2 '14 at 9:41
  • I tested it. I get nothing with that. Maybe to try with $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');, or something else? – Advanced SEO Jul 2 '14 at 10:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.