Is there a hook available that returns the featured image, once a featured image is set to a post?

I checked Which action hook can I use when a featured image has been selected and the action hooks mentioned does not get executed when the featured image is added.

  • 1
    the image choice is saved when the post is saved then informations on this other question are still valid.
    – Kaperto
    Commented Aug 17, 2018 at 17:07
  • @Kaperto Thanks I am able to get the _thumbnail_id if the user saves the post. But user need not to save the post to set the featured image. In this case how do I get the featured image? Commented Aug 17, 2018 at 17:21

1 Answer 1


If you wanna catch the event before saving the post, you won't be able to do this with PHP - setting the featured image is done with JavaScript (there is a hidden field and it's value is populated with JS when user picks a thumbnail from Media Uploader. Also the thumb preview is rendered with JavaScript.) So WordPress hooks won't be useful here, you need to look for a JavaScript event.

Good news is that you can still work with JS an wp.media API like this:

// listen for featured image selection event
wp.media.featuredImage.frame().on( 'select', function(){

    // get the selected image ID
    var thumb_id = wp.media.featuredImage.get();

    // there you go, thumb_id is the picked image ID
    console.log( thumb_id );

This would get fired every time a user sets a thumbnail from the Uploader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.