Using WordPress ‘media_submitbox_misc_sections’ PHP filter

The media_submitbox_misc_sections WordPress PHP filter allows you to customize the audio and video metadata fields displayed in the publish meta box.

Usage

add_filter('media_submitbox_misc_sections', 'your_custom_function', 10, 2);

function your_custom_function($fields, $post) {
    // your custom code here
    return $fields;
}

Parameters

  • $fields (array) – An array of the attachment metadata keys and labels.
  • $post (WP_Post) – WP_Post object for the current attachment.

More information

See WordPress Developer Resources: media_submitbox_misc_sections

Examples

Add a custom metadata field

Add a custom metadata field called “Director” to the publish meta box.

add_filter('media_submitbox_misc_sections', 'add_director_field', 10, 2);

function add_director_field($fields, $post) {
    $fields['director'] = __('Director', 'text_domain');
    return $fields;
}

Remove a metadata field

Remove the “Length” metadata field from the publish meta box.

add_filter('media_submitbox_misc_sections', 'remove_length_field', 10, 2);

function remove_length_field($fields, $post) {
    unset($fields['length']);
    return $fields;
}

Change the label of a metadata field

Change the label of the “File Type” metadata field to “Media Type”.

add_filter('media_submitbox_misc_sections', 'change_file_type_label', 10, 2);

function change_file_type_label($fields, $post) {
    $fields['file_type'] = __('Media Type', 'text_domain');
    return $fields;
}

Add a metadata field conditionally

Add a custom metadata field called “Album” only for audio attachments.

add_filter('media_submitbox_misc_sections', 'add_album_field', 10, 2);

function add_album_field($fields, $post) {
    if (strpos($post->post_mime_type, 'audio/') !== false) {
        $fields['album'] = __('Album', 'text_domain');
    }
    return $fields;
}

Modify multiple metadata fields

Add a custom metadata field called “Producer” and remove the “Dimensions” field.

add_filter('media_submitbox_misc_sections', 'modify_metadata_fields', 10, 2);

function modify_metadata_fields($fields, $post) {
    $fields['producer'] = __('Producer', 'text_domain');
    unset($fields['dimensions']);
    return $fields;
}