Using WordPress Media Uploader in Plugin or Theme

WordPress media Uploader is very Good which can also be used in your Themes or Plugins for uploading logo’s or anything else, WordPress Media Uploader makes it easy to upload files easily by the Users that is a plus point

So now lets begun, it is Easy to implement the WordPress Media uploader, first of all prepare an Piece of HTML like the below one :

<tr valign="top">
<th scope="row">Upload Image</th>
<td><label for="upload_image">
<input id="upload_image" type="text" size="36" name="upload_image" value="" />
<input id="upload_image_button" type="button" value="Upload Image" />
<br />Enter an URL or upload an image for the banner.

Now we are going to add some scripts so add this below code :

function my_admin_scripts() {
wp_register_script('my-upload', WP_PLUGIN_URL.'/my-script.js', array('jquery','media-upload','thickbox'));

function my_admin_styles() {

if (isset($_GET['page']) && $_GET['page'] == 'my_plugin_page') {
add_action('admin_print_scripts', 'my_admin_scripts');
add_action('admin_print_styles', 'my_admin_styles');

in the above code replace my_plugin_page with your page string for example


So in the above line you can see the String theme-options is the string

Now here comes the my-script.js code :

jQuery(document).ready(function() {

jQuery('#upload_image_button').click(function() {
 formfield = jQuery('#upload_image').attr('name');
 tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
 return false;

window.send_to_editor = function(html) {
 imgurl = jQuery('img',html).attr('src');


Now you have Successfully implemented WordPress Media Uploader in your Theme or Plugin

Thank you Matt for this Trick

Subscribe to WPDEN