I am writing a plugin for Wordpress and am wondering how to add an extra button to the media uploader that says something like "add to album". I can't seem to find info on how other developers have managed to get this done. Thanks :)

3 Answers 3


When i needed to do something similar i used the admin_print_scripts-media-upload-popup hook to add my own js/Jquery code to insert a button and handled it's click event with ajax.

something like this:

function add_my_media_button(){
jQuery(document).ready(function() {
    //loop over all attachments
        if (jQuery(this).next().attr('id') != ""){
            //get attachment id
            var att_id = jQuery(this).next().attr('id');
            att_id = att_id.replace("send[", "");
            att_id = att_id.replace("]", "");
            //insert button
            jQuery(this).append('<a href="#" class="button add_to_album" rel="'+ att_id +'" id="add_to_album['+att_id+']" name="add_to_album['+att_id+']">add to album</a>');

    //add handler for click
    jQuery(".add_to_album").live("click", function(){
        //do  your thing here
        alert("add to album click");
  • Thanks, that works like a charm. Do you know any way to use this button to close the thickbox? tb_remove doesn't work (i guess it's not loaded in the iframe). The rest of the data is already saved by then (i'm using the uploader just to upload attachments). Commented Dec 15, 2011 at 12:16
  • I added the ajax functionality(the button click) handler from admin_footer at the page that calls the media uploader.
    – Bainternet
    Commented Dec 15, 2011 at 12:20
  • You're talking about this code right? //add handler for click jQuery(".add_to_album").live("click", function(){ //do your thing here alert("add to album click"); )}; I can get this to work just fine, but I want to close the thickbox in this handler and can't get it to work. Commented Dec 15, 2011 at 12:30
  • yes that is what I'm talking about, this function i add using admin_footer hook on the page itself , before i even call the media uploader and if you use it there you will be able to use tb_remove();
    – Bainternet
    Commented Dec 15, 2011 at 12:35

I managed to get it done this way:

Adding JS to the media uploader:

function mediabutton(){

    wp_register_script( 'mediabutton', ''.WP_PLUGIN_URL.'/magic-gallery/js/mediabutton.js', null, null);
    wp_enqueue_script( 'mediabutton');


add_action('admin_print_scripts-media-upload-popup','mediabutton'); // Adding insert button

And then using this JS:

jQuery(document).ready(function() {

    jQuery('<a href="#" id="insert_gallery" class="button">Return to gallery</a>').insertAfter('.ml-submit');   

    jQuery('#insert_gallery').live('click',function() {

        self.parent.tb_remove(); // This closes the thickbox



Then I hooked into tb_close like this:

tb_remove = function () { 

    // Your code here
    alert('closing thickbox');

    // Original tb_remove code

    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6

        jQuery("body","html").css({height: "auto", width: "auto"});



    return false;

Or you can add a new tab, containing whatever you want .

function my_media_menu($tabs) {
$newtab = array('tabname' =&gt; __('TextInMenu', 'yourname'));
return array_merge($tabs, $newtab);
add_filter('media_upload_tabs', 'my_media_menu');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.