Adding WordPress 3.5 Media uploader to plugin / theme’s setting page

Many often developers require to provide a media uploader button in their theme’s or plugin’s setting page. The WordPress 3.5 media uploader (the one that was released with WordPress 3.5) is extremely simple to use and can be included in the admin pages with just a few lines of code.
So for the sake of this tutorial lets create a custom submenu page below the tools submenu page.

All the codes shown in this tutorial will go in your active theme’s function.php file.
In your dashboard, you should see a ‘Media Uploader Tutorial’ page below the tools submenu page as shown below.
media-uploader-tutorial
Now, what we want is whenever any one clicks the upload button the WordPress media uploader should pop up.
Since this is our custom page (not the default WordPress ‘Post’ or ‘Page’ as would be the case if we were adding the media uploader in a metabox), so we will have to enqueue the ‘wp_media_enqueue’.

Now the platform is set. To use the media uploader we just need to add the below jQuery code in the function media_uploader_tutorial_callback

And that’s it. If you click on the upload button now then you should see the media uploader.

Leave a Reply

Your email address will not be published. Required fields are marked *