Wordpress: Remove attachment fields

后端 未结 3 1839
悲哀的现实
悲哀的现实 2021-02-01 22:30

How do I remove attachment fields, like description and alt in media library of Wordpress attachments?

The following code use to work on old Wo

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 23:25

    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:

    wp.media.view.Attachment.Details.prototype.template = wp.media.template( 'attachment-details-custom' );
    

    Similarly you can override the micro template #tmpl-attachment-details-two-column with #tmpl-attachment-details-two-column-custom using:

    wp.media.view.Attachment.Details.TwoColumn.prototype.template = wp.media.template( 'attachment-details-two-column-custom' );
    

    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:

    Modified template

    Code:

    /**
     * Override the "Attachments Details" Backbone micro template in WordPress 4.0
     *
     * @see https://stackoverflow.com/a/25948448/2078474
     */    
    
    add_action( 'admin_footer-post.php', 'modified_attachments_details_template_so_25894288' );
    
    function modified_attachments_details_template_so_25894288() 
    {?>
            
      
        

    2) The following code example should remove the Caption, Alt Text and Description fields from the Attachments Details Two Column template:

    Screenshot:

    Modifed template

    Code:

    /**
     * Override the "Attachments Details Two Column" Backbone micro template in WordPress 4.0
     *
     * @see https://stackoverflow.com/a/25948448/2078474
     */    
    
    add_action( 'admin_footer-upload.php', 'modified_attachments_details_two_column_template_so_25894288' );
    
    function modified_attachments_details_two_column_template_so_25894288() 
    { ?>
            
      
        

    You can hopefully modify this to your needs.

提交回复
热议问题