How to Hide Buttons within the Media Window in WordPress

Snippets by IsItWP

Do you want to hide buttons and input fields within the media attachment window? Adding this snippet to the functions.php of your WordPress theme will help you to easily do that.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function attachment_fields($form_fields, $post) {
    if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
        $form_fields['image_alt']['value'] = '';
        $form_fields['image_alt']['input'] = 'hidden';
        $form_fields['post_excerpt']['value'] = '';
        $form_fields['post_excerpt']['input'] = 'hidden';
        $form_fields['post_content']['value'] = '';
        $form_fields['post_content']['input'] = 'hidden';
        $form_fields['url']['value'] = '';
        $form_fields['url']['input'] = 'hidden';
        $form_fields['align']['value'] = 'aligncenter';
        $form_fields['align']['input'] = 'hidden';
        $form_fields['image-size']['value'] = 'thumbnail';
        $form_fields['image-size']['input'] = 'hidden';
        $form_fields['image-caption']['value'] = 'caption';
        $form_fields['image-caption']['input'] = 'hidden';
        $form_fields['buttons']['input'] = 'hidden';
    return $form_fields;
add_filter('attachment_fields_to_edit', 'attachment_fields', 15, 2 );

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.

Comments   Leave a Reply

  1. Florian Schroiff November 28, 2012 at 7:39 am

    I wonder if there is a way to influence the order of fields. My caption field is now always the last one…

  2. is it possible to show “All Types” instea dof “Images” as the default view in the “Media Library” tab?

  3. louisville chiropractic July 28, 2011 at 5:44 am

    i want to try this in one of my wordpress.

    1. Sure just copy and paste the code into your functions.php file and you will be ready to go.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!