Display featured image file size, extension, filename, type, orientation? How to display some information of featured image in post.

I need to display like this in post:

Detail Of Easter Desktop Wallpaper Widescreen Posted : February 13, 2017 At 9:46 Am

Author : Admin

Category : Easter

Tags : Beautiful, Cool, Desktop

Viewed : 1334 Visitor

File Size : 324 KB

File Type : Image/Jpeg

Resolution : 2560x1920 Pixel

Download : Smartphone ° Tablet ° Desktop (Original)

Download Many Resolution: Click Here (To Attachment Page)

pls, i am newbie, make it easy for me to understand. thnks

  • This is quite open ended, you will need to break this apart into smaller multiple questions, else it's quite broad. E.g. 10 questions each for the 10 steps in baking a cake, vs what we have here "how to cake?" – Tom J Nowell Feb 18 '19 at 4:19
  • I can understand your problem except this "Download : Smartphone ° Tablet ° Desktop (Original)" . can you please explain me what is this . so can give you full code in answer. – Tanmay Patel Feb 18 '19 at 4:22

The featured image is just an attachment, and you can retrieve its post ID via get_post_thumbnail_id, e.g.

$featured_image_id = get_post_thumbnail_id( $post );

At which point you're dealing with a standard post of type attachment. Other than checking that there is a featured image, no special handling is needed and it can be treated as any other attachment post.

In fact, internally setting the featured image is just putting a post ID in a particular post meta field.

function get_post_thumbnail_id( $post = null ) {
    $post = get_post( $post );
    if ( ! $post ) {
        return '';
    return get_post_meta( $post->ID, '_thumbnail_id', true );

Though I would recommend using the function instead of going straight for the post meta.

As for how to get the size, type, format of an attachment post, that's another question that you should open a new question for ( or refer to the main good answers that already exist )

|improve this answer|||||

Here is the code as you wanted except this "Download : Smartphone ° Tablet ° Desktop (Original)". you can see in this screenshot http://prntscr.com/mmidnl

1. you can below code in functions.php file for visitors count. Reference: https://www.themexpert.com/blog/track-display-post-views-in-wordpress

function to display number of posts.

function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 Visitor";
    return $count.' Visitors';

function to count views.

function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        update_post_meta($postID, $count_key, $count);

Remove issues with prefetching adding extra views

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); 

2. Put this below code in single.php file.

This part of the tracking views code will set the post views. Just place this code below within the single.php file inside the WordPress Loop.

<div class="data">
<div>Detail Of <?php the_title(); ?> Posted : <?php the_time('F j, Y'); ?> At <?php the_time('g:i a'); ?></div>
<div>Author : <?php the_author(); ?></div>
<div>Category : <?php the_category( ', ' ); ?></div>
<div><?php the_tags( 'Tags: '); ?> </div>
<div><?php setPostViews(get_the_ID()); ?>Viewed : <?php echo getPostViews(get_the_ID()); ?></div>
<div><?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); $img_s = get_headers($image_data[0], 1); $img_size_wd =  $img_s["Content-Length"]/1024; $img_size_kb = number_format((float)$img_size_wd, 2, '.', ''); ?>File Size : <?php echo $img_size_kb; ?> KB</div>
<div><?php $img_id = get_post_thumbnail_id($post->ID); $type =  get_post_mime_type( $img_id ); ?>File Type : <?php echo $type; ?></div>
<div><?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full" ); ?> Resolution : <?php echo $image_data[1]; ?> x <?php echo $image_data[2]; ?> Pixel</div>
<div><?php $img_id = get_post_thumbnail_id($post->ID); ?>Download Many Resolution: <?php echo '<a href="'. get_attachment_link($img_id) . '">Click Here</a>'; ?></div>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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