4

I've been searching high and low for an answer.

I simply want to remove the Alternate Text, Caption, Description and Link URL-fields from the uploader and gallery view.

I seem that every thing else than this Media-thingy can be removed.

Thanx for helping out:)

2

5 Answers 5

3

You can do this via a filter. Add the following to functions.php. You can also add your own fields this way...

// edit fields in media upload area
add_filter('attachment_fields_to_edit', 'remove_media_upload_fields', 10000, 2);
function remove_media_upload_fields( $form_fields, $post ) {

    // remove unnecessary fields
    unset( $form_fields['image-size'] );
    unset( $form_fields['post_excerpt'] );
    unset( $form_fields['post_content'] );
    unset( $form_fields['url'] );
    unset( $form_fields['image_url'] );
    unset( $form_fields['align'] );

    return $form_fields;
}

The example above strips out more than you need to but if you do a print_r() on the $form_fields variable you'll see what's available to add/remove.

2
  • 3
    Doesn't appear to work any more. $form_fields is empty for this filter. Commented Apr 3, 2013 at 19:11
  • 2
    Doesn't work on WP 3.5+ Commented Apr 26, 2017 at 18:42
1

Unfortunately it looks like this changed quite a bit in WP3.5 when they upgraded the media library. That filter's $form_fields parameter doesn't contain the defaults any more. The only solution I've found so far is to forcibly remove the markup from the view using buffering:

This is extremely fragile - any change to the WordPress core might break this

function wpse45562_remove_media_fields( $buffer ) {
    // remove the 'caption' block
    $buffer = preg_replace( '~<p>\s*<label\s*for="attachment_caption">.*?</p>~ims', '', $buffer );
    // remove the 'alt text' block
    $buffer = preg_replace( '~<p>\s*<label\s*for="attachment_alt">.*?</p>~ims', '', $buffer );

    // remove the 'description' box (and label separately)
    $buffer = preg_replace( '~<div\s*id="wp-attachment_content-editor.*?</div>~ims', '',   $buffer );
    $buffer = preg_replace( '~<label\s*for="content">.*?</label>~ims', '', $buffer );

    return $buffer;
}

function wpse45562_media_strip_buffer_start() { ob_start("wpse45562_remove_media_fields");  }
function wpse45562_media_strip_buffer_end() { ob_end_flush(); }

add_action('admin_head', 'wpse45562_media_strip_buffer_start', 10, 1);
add_action('admin_footer', 'wpse45562_media_strip_buffer_end', 10, 1);
4
  • I think there a some filters in the js backbone templates where the fields get added we might be able to co-opt. It certainly isn't straightforward any more though :( Commented Apr 4, 2013 at 9:27
  • I agree. For now I've opened a ticket over on Trac. If they're going to make it the same as any other post it should respond to remove_post_type_support(), at least. Commented Apr 4, 2013 at 21:43
  • Wouldn't this approach affect caching? Commented Apr 26, 2017 at 18:45
  • @ThatBrazilianGuy - I'm not sure what you mean. These fields are displayed in the dashboard. Having empty values for the media will not affect the caching. Commented Apr 26, 2017 at 22:49
1

Since WP 3.5, the simplest way is to just remove fields with CSS:

add_action('admin_head', 'custom_remove_attachment_fields');
function custom_remove_attachment_fields() {
    ?><style type='text/css'>
        .attachment-info .setting.has-description,/* Alternative Text */
        .attachment-info #alt-text-description,/* Alternative Text description */
        .attachment-info .setting[data-setting="title"],
        .attachment-info .setting[data-setting="caption"],
        .attachment-info .setting[data-setting="description"],
        .attachment-info .setting[data-setting="url"],
        .attachment-info .media-types.media-types-required-info /* Required info */ {
            display: none;
        }
    </style><?php
}

This is focused on images, but you can add anything to it...

0

I know it's a really old question, but I was looking for a feature like this right now, and @Jake 's answer was the closest to the solution I got myself, which is adding to the style.css

.media-sidebar .setting.has-description,
.media-sidebar #alt-text-description,
.media-sidebar .setting[data-setting="title"],
.media-sidebar .setting[data-setting="caption"],
.media-sidebar .setting[data-setting="description"],
.media-sidebar .setting[data-setting="url"],
.media-sidebar .media-types.media-types-required-info,
.media-sidebar .compat-item {
    display: none !important;
}

this removed the whole meta fields part, leaving image details like file name, image size and upload date.

-2

The sanchothefat's Answer is correct, really Works like a charm.

Just for increase his answer, you can use unset( $form_fields['image_alt'] ); to remove the Alternate Text.

Thanks for Answering sanchothefat, it Helped me.

1

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.