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:)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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*<labels*for="attachment_caption">.*?</p>~ims', '', $buffer );
// remove the 'alt text' block
$buffer = preg_replace( '~<p>s*<labels*for="attachment_alt">.*?</p>~ims', '', $buffer );
// remove the 'description' box (and label separately)
$buffer = preg_replace( '~<divs*id="wp-attachment_content-editor.*?</div>~ims', '', $buffer );
$buffer = preg_replace( '~<labels*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);
Method 3
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…
Method 4
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.
Method 5
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0