On searching for a solution, I found the following codes to add col on media page:

add_filter ( "manage_upload_columns",  'upload_columns' );
add_action ( "manage_media_custom_column", 'media_custom_columns' , 0, 2 );

The result is close to what I want, but I need to implement it on thickbox gallery tab-- I want to add an "Include" checkbox column for the media items.

How can I achieve this?

This checkbox would serve as the include part in the gallery shortcode [gallery include="23,39,45"].

But, the shortcode is not written in the post content. The gallery is added for each post by a theme template.

[update] To save the ids we get from brasofilo's scripts, I added name="include_ids" in the shortcode line and added this:

add_action( 'edit_attachment',  array ($this,'save_to_parent_meta' ));

function save_to_parent_meta(){
if ( isset($_POST['include_ids']) && !empty($_POST['include_ids']) ) {
update_post_meta( $_REQUEST['post_id'],'include_ids',$_POST['include_ids']);

This will save the ids to parent post's meta if 'includes_ids' filed is not empty. Nearly perfect. But, when the tab is loaded, the include_ids field is empty, and all checkbox is unchecked. Users might think they need to check again even if they don't want to make change.

  • 1
    I'm not sure what do you mean by "include checkbox". I suppose you want to add some functionality to it, no? I did some jQuery manipulation to add a virtual image size column in this answer. You may also take a look at the plugin Advanced Custom Fields, as it does some heavy manipulation of the TB window.
    – brasofilo
    Jun 5, 2012 at 10:58
  • @brasofilo , the solution you posted on image-size column is what I need. But, I also need this column to be checkbox instead of image-size. If a raw's checkbox is checked, that means the user like to include this item in this garlary. That's what I meant by "include" checkbox. How can I use your code to load a column of checkbox?
    – Jenny
    Jun 5, 2012 at 23:53
  • Jenny, I believe one has to completely rebuild the TB to achieve what you want... not an easy task, IMO...
    – brasofilo
    Jun 5, 2012 at 23:58
  • I think I finally see what's your goal... Do you want this shortcode [gallery include="23,39,45"] built automatically based on the user selection through checkboxes? Codex reference: codex.wordpress.org/Gallery_Shortcode
    – brasofilo
    Jun 6, 2012 at 0:16
  • @brasofilo , yes,that's the goal, but a bit different implementation-- When user post, they do not need to write done the shortcode. The gallery is added for each post by theme template. But they do need to go to Gallery Tab to make the selection.
    – Jenny
    Jun 6, 2012 at 4:31

1 Answer 1


While researching I found what may be a duplicate, but I'm really not sure, as this one deals with sending the value somewhere else...

There, I learned that there's a plugin for what I was already coding ( Multiple Galleries) and it injects the include attribute when inserting the gallery.

Nonetheless, a worthy exercise and a joint venture with a StackOverflow'er.


Appears in the Gallery and Library tabs.
The idea is to copy/paste the value of the selected images and use it manually.
Usage can be in a Custom Field, from where it is read in some template page.

Result of the Code

enter image description here

The Code

add_action( 'admin_head-media-upload-popup', 'wpse_53803_script_enqueuer' );

function wpse_53803_script_enqueuer() 
    if( $_GET['tab'] == 'gallery' || $_GET['tab'] == 'library' ) 
           <style>#media-upload th.order-head {width: 5%} #media-upload th.actions-head {width: 10%}</style>
           <script type="text/javascript">
        jQuery(document).ready( function($) {
              * Add Input Text Field
             $('<span>Copy this to use in the Gallery shortcode as the "include=image-ids" (<a href="http://codex.wordpress.org/Gallery_Shortcode" target="_blank">documentation</a>): </span><input type="text" id="shortcode" style="width:99%;clear:both" /><span></span><hr style="width:99%;opacity:.5" />').prependTo('p.ml-submit:first');

             * OnClick Populate/Depopulate Text Field
                var checkedIds = $('input[type="checkbox"][name^="gal-item"]:checked').map(function(){
                    return parseInt($(this).prop('name').replace(/gal-item-/,''));


             * Iterate through the Media Items and Add a CheckBox
               var id = $(this).next('.slidetoggle')
                                .replace(/media-head-/, '');
               var filename = $('<label>Add to gal-list <input type="checkbox" name="gal-item-'+id+'" id="gal-item-'+id+'" value=""  /></label>')
               filename.css('float','right').css('margin','12px 40px 0 0');
  • it works! Thanks for the solution and the time you spend on it! By the way, do I need to do anything to save the checkbox selection results?
    – Jenny
    Jun 7, 2012 at 1:55
  • @brasofilio , Now I understand-- need to copy the ids manually. How can I save it for later use automatically?
    – Jenny
    Jun 7, 2012 at 3:04
  • @Jenny : no automation here, you need to paste the value inside a Custom Field, so it is saved and can be used in your template...
    – brasofilo
    Jun 7, 2012 at 7:28
  • I got an idea, I change "Copy this to.." as a hidden input field, then, hook it up with "Save all changes" to save the ids as post's meta. I will try to see how it goes. Thanks!
    – Jenny
    Jun 7, 2012 at 8:39
  • If you are so kind, when you have the code, please add it to my answer :) Or, if they are major changes, post a new answer with your full working code!
    – brasofilo
    Jun 7, 2012 at 8:46

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.