0

I'm trying to get a specific post's thumbnail by using the post's ID. I have this code snippet in my index.php file

<?php get_the_post_thumbnail(64 , 'post-thumbnail', array( 'class' => 'img-format-big' ) ); ?>

It doesn't return any image/thumbnail at all. Anything wrong with the code?

1

Make sure to use echo with get_the_post_thumbnail():

echo get_the_post_thumbnail(64 , 'post-thumbnail', array( 'class' => 'img-format-big' ) );

In WordPress, a rule of thumb (no pun intended) is to use echo with functions prefixed with get_. Functions prefixed with the_ on the other hand, display their output immediately (e.g. the_post_thumbnail() ).

| improve this answer | |
  • 1
    Oh wow I can't believe I missed that bit! It was such an elementary mistake, thank you for the help! – eastwind May 17 '17 at 3:12
  • Happy to help! Don't worry it happens to everybody and is more or less a rite of passage in the WP world :-) – Dave Romsey May 17 '17 at 3:14
  • 1
    echo with get_ prefix and no echo with the_ prefix`, wow didn't aware of this. Till now I used echo when the function don't work in regular way by thinking if it is not showing output then might show with echo hahaha. This is really great information to know :) – Rishabh May 17 '17 at 4:38

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.