Get ID of featured image using “get_post_thumbnail_id(the_ID())” – without printing to screen?

I’m using the code:

get_post_thumbnail_id(the_ID())

to get the ID of a post thumbnail image, but whenever I call this it outputs the ID to screen. I just want to get the value to use in another function, without it echoing anywhere.

Read More

How do I do this?

Related posts

Leave a Reply

1 comment

  1. You should not use the_ID() in this case, since it will echo the ID, use instead get_the_ID() to return it.

    So please try this instead:

    $thumb_id = get_post_thumbnail_id( get_the_ID() );
    

    to get the ID of a post thumbnail image.

    The general rule is that the_*() functions will echo the output, but get_*() functions will return it. But of course there are exceptions to every rule, so be careful 😉 If in doubt test it, consult the Codex or check out the source code.