How do I remove attachment fields, like description
and alt
in media library of Wordpress attachments?
The following code use to work on old Wordpress versions (pre 3.5):
function remove_attachment_field ( $fields ) {
unset( $fields['image_alt'] ); // Removes ALT field
return $fields;
}
add_filter( 'attachment_fields_to_edit', 'remove_attachment_field', 15, 1 );
But since then, I have not found a working solution.
Do anyone know a solution?
Clarification on which fields I would like to remove:
The styles can be printed on
/wp-admin/post.php
usingadmin_print_styles-$page
, and selecting the elements using the data attribute.It's possible to detect the current post type and only apply the rules on a given type:
The above solution by @brasofilo should work well, but we can also use this great answer by @EricAndrewLewis as a guideline on how to override the Backbone micro templates.
Overriding the Backbone micro templates - short version:
You can override the micro Backbone template
#tmpl-attachment-details
with your custom#tmpl-attachment-details-custom
using:Similarly you can override the micro template
#tmpl-attachment-details-two-column
with#tmpl-attachment-details-two-column-custom
using:Overriding the Backbone micro templates - long version:
Here you can get the media templates used by the WordPress core.
1) The following code example should remove the Caption, Alt Text and Description fields from the Attachments Details template:
Screenshot:
Code:
2) The following code example should remove the Caption, Alt Text and Description fields from the Attachments Details Two Column template:
Screenshot:
Code:
You can hopefully modify this to your needs.
Try this: