I added few custom fields via attachment_fields_to_edit and would like to show them only when certain theme or page builder image option opens the wp.media.iframe.

Currently they are visible regardless what button opens the uploader for example post "Add media" would not have any use for this option

enter image description here

So I am kinda trying to find a "hook" that would let me know what option is currently using the uploader.

What I am trying to stay away from is doc click events

$(document).on("click", '.some-button-class', function() {
    //  .some-button-class is clicked

and would rather use something like this if possible,

wp.media.frame.on( 'open', function(el) {

    //  some-button-class has opened

Is there a way to do this?

1 Answer 1


I think I got it ,

if (wp.media) {
    wp.media.view.Modal.prototype.on('open', function(data) {

let me know if there is better solution.

  • Still works in 2022
    – Gavin
    Feb 3, 2022 at 11:06

Your Answer

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

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