WordPress Using Media uploader in your plugin

Hi Guys,

I have to agree that with wordpress, possibilities are infinite (may be). As I am still learning WordPress API and still have to master the art of Hooks and Crooks (I mean filters) :),

I had developed very basic plugins for my couple of website but they were really basic. So everyday with WordPress I am learning something new. Last week I learned how can I use the available Media Uploader that ships with WordPress. So rather to reinvent the wheel, you can use whatever is already available

Ok so lets get started.

First You will need couple of includes so in you admin_init action or whichever hook you are using to enqueue the scripts put this code there


This makes sure that thickbox (modaled window) and media-upload scripts are available. As you notice that we’ve imported thinkbox style too. WordPress knows where these scripts are so you don’t have to worry about the paths here.

Ok So this is done Now we will create a very basic form as shown below. This form will be on one of your Admin pages.

[geshi lang=”html5″ nums=”1″ target=”_self” ]

Upload CSV

Upload your CSV file..



Now that our HTML Form has been setup lets do some jQuery magic to open media uploader page. you can place this script just under your form or you can include it in your JS file. because we are using document.ready (pseudo) so the script wont execute until the page get loaded completely.

[geshi lang=”javascript” nums=”1″ target=”_self” ]

Ok so this way we will have our file or image uploaded and have path of the Image which we can store in database or do other manipulations.


I hope this Tip will help you.

I will be writing on how to add custom buttons on top of content editor soon so stay tuned

Till then Adios!




  1. Excellent innovation to people very good plugin still trying to learn it.

  2. Good information , nice content very useful all of us, thank u.

  3. This is really good help. thanks

  4. Thanks Jaspreet… finally a good explanation to implement the media uploader in my custom plugin!
    Thanks again, now I can start my small project 🙂

  5. Thanks Jaspreet… It’s indeed a helpful one..And yes, with wordpress we are bound to learn something new everyday as it is with any open source mediums, the more we use, the more it expands and in-turn the more we learn..:)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.