How to use media upload on theme option page?

You are most likely to save the url of the image and not the whole image tag,
and there is a great tutorial that explains just how to use the media uploader in your own theme or plugin:
http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

update

In case of using this in a meta box you will need the post id so change the js code from:

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

to

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

Leave a Comment