Support » Themes and Templates » How do I echo a post thumbnail's width

  • Resolved gavargas


    I am doing a project where I require echoing into text the size of the thumbnail in order to automatically resize a div according to this value. I looked into ways of trying to echo the WordPress variable $width but I cannot seem to be able to “echo” it, has anyone done something like this that could point me in the right direction?

Viewing 1 replies (of 1 total)
  • gavargas


    I found out how through the

    <?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>

    This is what I did:

    $cardimgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'single-thumb' );
    $imgwidth = $cardimgdata[1];

    Then I echo the value of the width [1]:

    <?php echo $imgwidth ?>

    single-thumb is the name of the thumbnail size I declared in the functions.php file you can substitute it for whatever you have on your functions.php file.

    For more information here is where I obtained the code from:

Viewing 1 replies (of 1 total)
  • The topic ‘How do I echo a post thumbnail's width’ is closed to new replies.