Create a custom image upload button in your WordPress plugin

I’m constantly writing plugins and creating customizations for clients, and I often need to create something that allows the user to upload images within a page on the dashboard. There are many ways to achieve this, but clearly the correct approach is to use WordPress’s native Media Uploader. This maintains consistency within the dashboard, and allows the user to use any images they’ve already uploaded to their site.

View & Download on GitHub

In my efforts to make this an easier process for myself to re-use the code whenever I needed a button, I decided to create a small jQuery plugin that will do the work for me. It is now available for download and use in your free or commercial projects.

preview

This plugin takes a the headache away, all you have to do is add a little HTML, and add a call to initialize the Media Uploader.

View & Download on GitHub

Additionally, the plugin will allow you to customize the default appearance, class and text. You can also customize the preview size, and it is compatible with Bootstrap Modals, so if you’re outputting the upload button in a modal, this will work just fine.

preview2

Leave a Reply