Using WordPress ‘attachment_submitbox_misc_actions’ PHP action

The attachment_submitbox_misc_actions WordPress PHP action fires after the ‘Uploaded on’ section of the Save meta box in the attachment editing screen.


add_action('attachment_submitbox_misc_actions', 'your_custom_function');
function your_custom_function($post) {
    // your custom code here


  • $post (WP_Post): The WP_Post object for the current attachment.

More information

See WordPress Developer Resources: attachment_submitbox_misc_actions


Add a Custom Field to the Attachment Submit Box

Add a custom field to the attachment submit box and save its value.

add_action('attachment_submitbox_misc_actions', 'add_custom_field');
function add_custom_field($post) {
    $custom_value = get_post_meta($post->ID, '_custom_field', true);
    echo '<label for="custom_field">Custom Field: </label>';
    echo '<input type="text" id="custom_field" name="custom_field" value="' . esc_attr($custom_value) . '" />';

add_action('edit_attachment', 'save_custom_field');
function save_custom_field($post_id) {
    if (isset($_POST['custom_field'])) {
        update_post_meta($post_id, '_custom_field', $_POST['custom_field']);

Display Attachment File Size

Display the file size of the attachment in the submit box.

add_action('attachment_submitbox_misc_actions', 'display_file_size');
function display_file_size($post) {
    $file_path = get_attached_file($post->ID);
    $file_size = filesize($file_path);
    echo '<p>File Size: ' . size_format($file_size) . '</p>';

Add a Custom Button

Add a custom button to the attachment submit box.

add_action('attachment_submitbox_misc_actions', 'add_custom_button');
function add_custom_button($post) {
    echo '<input type="button" class="button" id="custom_button" value="Custom Button" />';

Display Attachment Dimensions

Display the dimensions of an image attachment in the submit box.

add_action('attachment_submitbox_misc_actions', 'display_image_dimensions');
function display_image_dimensions($post) {
    if (wp_attachment_is_image($post->ID)) {
        $dimensions = wp_get_attachment_image_src($post->ID, 'full');
        echo '<p>Dimensions: ' . $dimensions[1] . ' x ' . $dimensions[2] . ' px</p>';

Change Attachment Title Placeholder

Change the placeholder text of the attachment title input field.

add_action('attachment_submitbox_misc_actions', 'change_title_placeholder');
function change_title_placeholder($post) {
echo '<script>
document.getElementById("title").setAttribute("placeholder", "Custom Attachment Title");