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.
How do I do this?
You should not use
the_ID()
in this case, since it will echo theID
, use insteadget_the_ID()
to return it.So please try this instead:
to get the
ID
of a post thumbnail image.The general rule is that
the_*()
functions will echo the output, butget_*()
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.