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


About Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at Co-founded Blog at
This entry was posted in php, wordpress and tagged . Bookmark the permalink.

One Response to Use WordPress media upload modal

  1. Antoine says:

    It’s work ! Thank you so much ! I search a solution for to much time :’)

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s