In current version of WordPress it is quite easy to expand the attachments fields using attachment_fields_to_edit filter, but in latest WordPress 3.5 RC2 it's not working. We can expand it using custom meta fields, but using this requires editing each attachment in Media tb. I was wondering if it is possible to expand fields in Attachment details in modal box with Media Library https://i.sstatic.net/sPM53.png (sorry for a link but I cannot add image, not enough reputation ;))

Thank you for any help.

  • Please update your question to reference the current stable release of WordPress 3.5, as RC2 was pre-release software.
    – EAMann
    Commented Dec 11, 2012 at 18:46

2 Answers 2


You can add inputs and fields to attachments by hooking into attachment_fields_to_edit. This will add fields to both the modal as well as the attachment editor. The catch I found is that WordPress (if anyone has experienced differently PLMK) doesn't save the extra fields data so you have to hook into a couple other items.

I have added a code sample to give you add idea of what you could do.

add_filter( 'attachment_fields_to_edit', 'xf_attachment_fields', 10, 2 );

function xf_attachment_fields( $fields, $post ) {

 $meta = get_post_meta($post->ID, 'meta_link', true);
 $fields['meta_link'] = array(
    'label' => 'More Media Management',
    'input' => 'text',
    'value' => $meta,
     // 'html' => '<div class="meta_link"><input type="text" /></div>',
   'show_in_edit' => true,
 return $fields;
add_filter( 'attachment_fields_to_save', 'xa_update_attachment_meta', 4);

function xa_update_attachment_meta($attachment){
  global $post;
  update_post_meta($post->ID, 'meta_link', $attachment['attachments'][$post->ID]['meta_link']);

add_action('wp_ajax_save-attachment-compat', 'xa_media_xtra_fields', 0, 1);
function xa_media_xtra_fields() {
  $post_id = $_POST['id'];
  $meta = $_POST['attachments'][$post_id ]['meta_link'];
  update_post_meta($post_id , 'meta_link', $meta);
  • Thanks for this. I needed to add return $attachment; to the xa_update_attachment_meta callback, but after that, it worked. Commented Jan 16, 2013 at 15:48
  • 3
    This thread seems abandoned by its OP, but I'm wondering if all this "compat" stuff is really where it's at in WP 3.5. Is there a new, current (as in "not backward compatible, but by design going forward") method to add this kind of thing in WP 3.5+?
    – k3davis
    Commented Jan 29, 2013 at 1:24

You should still be able to use attachment_fields_to_edit, however those fields are also added to the modal window now. You can direct a field to only show up in the modal or only show up on the edit page by using the "show_in_edit" or "show_in_modal" parameters. Both are boolean and both default to true. Take a look at this trac ticket explaining the behavior: http://core.trac.wordpress.org/ticket/22759#comment:1

You should be aware that they seem to now be prefixed with "compat-field-" in the class names.


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.