In many cases you might want to use the WordPress media uploader in your plugins, whether your plugin provides some sort of functionality that has to do with images or you simply want to allow for users to upload a logo or favicon. Whatever your reasons may be here we’ll go through the steps you need to take in order to make the WordPress media uploader work inside your plugins.

Just like using WordPress native color picker getting the uploader to work takes 3 easy steps:

  1. Your upload form HTML structure
  2. Your JavaScript file to make that HTML structure work

    Save this to a file called “mediauploader.js” and save it to the root of your plugin.
  3. A few scripts properly enqueued to your admin pages

    Now add this to the .php file were you want the uploader to work. What this bit of code does is enqueue the .js file we’ve just created on step 2 plus some other necesary core WP scripts

Tip 1: Remember this will only populate the “image_url” field with the image you just uploaded URL. You still need to save this value to the DB like you would save a regular text field.