WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I echo a post thumbnail's width (2 posts)

  1. gavargas
    Member
    Posted 1 year ago #

    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?

  2. gavargas
    Member
    Posted 1 year ago #

    I found out how through the

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

    This is what I did:

    <?php
    $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:

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

Topic Closed

This topic has been closed to new replies.

About this Topic