0
<a class="classname" href="<?php the_post_thumbnail_url( 'full' ); ?>">Full Image</a>

Im using this code: Output is text "Full Image" linked to the post url of the full featured image. What I want to achieve is to add dimensions to show for that image as f.e:

"Full Image 600x400" or Only "(600x400)"

Thanks!

0

Add this function to your functions.php file:

function show($size = NULL) {
    global $post;
    $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
    if(isset($size)){
        $image_data_array = wp_get_attachment_image_src($post_thumbnail_id,$size);
    }else{
        $image_data_array = wp_get_attachment_image_src($post_thumbnail_id);//Default value: 'thumbnail'
    }
    echo $image_data_array[1]."x".$image_data_array[2];//here you can add more chars of strings if you want
}

and use it like this:

<a class="classname" href="<?php the_post_thumbnail_url( 'full' ); ?>">Full Image <?php show('full'); ?></a>

this is outputting WidthxHeight, you can use any default image size thumbnail, medium, medium_large, large, full or any custom size you have added using add_image_size()

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.