Journal of a Web Professional in Brussels

Customize the wordpress Upload interface

WordPress can be customized a lot if you are ready to get your hands dirty with the functions.php file. This is useful to unclutter the interface for your less computer-savvy users, and basically, to reduce the complexity of their experience as much as possible (less complexity, less chance to make errors and experiment frustration).

One of the interfaces they'll probably use a lot is the one that appears when they want to add an image or media file: the "Add an attachment" screen.

Add This function to your theme's functions.php to hide all fields that you want to hide to your "author" users

PHP:
  1. function remove_attachment_fields($form_fields) {
  2. if ( substr( $post->post_mime_type, 0, 5 ) == ‘image’) {
  3.      $form_fields['image_description']['input'] = 'hidden';
  4.     if (current_user_can('author')){
  5. // Alternative text
  6.     $form_fields['image_alt']['value'] = '';
  7.         $form_fields['image_alt']['input'] = 'hidden';
  8. // Description
  9.         $form_fields['post_excerpt']['value'] = '';
  10.         $form_fields['post_excerpt']['input'] = 'hidden';
  11. // Title     
  12.        $form_fields['post_title']['value'] = '';
  13.         $form_fields['post_title']['input'] = 'hidden';
  14.         $form_fields['post_content']['value'] = '';
  15.         $form_fields['post_content']['input'] = 'hidden';
  16. // Url associated to the image's click behaviour
  17.         $form_fields['url']['value'] = '';
  18.         $form_fields['url']['input'] = 'hidden';
  19. // image alignment
  20.         $form_fields['align']['value'] = 'aligncenter';
  21.         $form_fields['align']['input'] = 'hidden';
  22. // image size that will be injected inside your post content if you insert it
  23.         $form_fields['image-size']['value'] = 'thumbnail';
  24.         $form_fields['image-size']['input'] = 'hidden';
  25.         $form_fields['image-caption']['value'] = 'caption';
  26.         $form_fields['image-caption']['input'] = 'hidden';
  27.         $form_fields['buttons']['input'] = 'hidden';
  28.         return $form_fields;
  29.     }
  30. }
  31. }
  32. add_filter('attachment_fields_to_edit','remove_attachment_fields', 15, 2);

The Conversation

4 Responses to Customize the wordpress Upload interface

  1. Torbjörn says:

    Hi and thanks for the tips. I am trying to solve a similar problem (adding text to the ‘Upload media from computer’ screen. See But i haven´t found a solution yet. Any tips?

  2. pixeline says:

    Hi torbjörn,
    Perhaps this tutorial on Creating custom fields for attachments in WordPress could help? http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/

  3. Hello. I wanted to thank you for this. It was exactly what I needed.

    There is a tiny typo however. Line 2 should read:
    if ( substr( $post->post_mime_type, 0, 5 ) == ‘image’) {

    thank you again.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Belgians do IT better _