Use WordPress media upload modal

In a project I needed selecting uploaded attachments and the media upload modal would fit flawlessly.

Before calling wp_enqueue_script() I had to add wp_enqueue_media().

The HTML part required a <button> with the following attributes data-editor="editor-id" class="button insert-media"

In JavaScript part I used the attachment value:

$( document ).on( 'click', '.insert-media', function( event ) { = function( props, attachment ) {
      $( '#output' ).val( attachment.url );

Resources that helped me were and


Author: Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at Co-founded Blog at

One thought on “Use WordPress media upload modal”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s