I am using the metabox.io plugin. I am looking for a way to open the new WordPress Gutenberg editors featured image modal onClick of a button inside my custom metabox.

Is there a function that I can use in order to make the featured image modal popup onClick of a button?

Basically, I want to replicate the functionality of the onClick of “Set featured image”.

enter image description here

So the Featured Image Modal pops up.

enter image description here

Thanks for your help.

  • Do you have this working in the classic editor? If so, does that code not work as is in GB? – Tom J Nowell Dec 18 '18 at 17:00
  • Yes, I had it working in the classic editor by calling: wp.media.featuredImage.frame().open(); That's not working in Gutenberg though. – Share Web Design Dec 18 '18 at 21:22
  • I'm pretty sure the new block editor uses the same media library API, though it's a little weird that you're duplicating the featured image UI. Even if you manage to open that UI, you'd then need to update the editor to use the new selection for its internal data, and listen out for when the other featured image UI is used and update your own – Tom J Nowell Dec 18 '18 at 21:25
  • In Gutenberg, wp.media.featuredImage.frame().open(); opens the featured image modal the same as it did in the classic editor. It just doesn't set it in the sidebar Featured Image metabox after you add the image. I know the featured image metabox is now a React component. Could that have something to do with it? – Share Web Design Dec 18 '18 at 21:39
  • Also, I already have my image in my metabox updating in both Gutenberg and the Classic editor, that part is worked out. – Share Web Design Dec 18 '18 at 21:47

This was solved for me by Brandon Payton on Wordpress.org's Gutenberg support forum:


He was even awesome enough to create a gist:


You the man Brandon!!

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.