It's WordPress!

Themes, Plugins, Tips, Tricks and More!

Add Additional File Types to WordPress Media Library

Add Additional File Types to WordPress Media Library

Posted by Geoffrey Fortier On September - 18 - 2011 Viewed:  

photo credit: bionicteaching

Although the Media library feature in WordPress spends most of its life uploading and storing images and graphics, it actually has quite a bit more functionality.  It can serve as storage for various files, both multimedia and traditional.  This allows WordPress site owners to provide downloads of documents, embed audio and video files and more.

For security reasons, the default installation of WordPress restricts the types of files you can uploaded to a list of commonly accepted, safe(r) formats.  These include:

Images

  • .jpg
  • .jpeg
  • .png
  • .gif

Documents

  • .pdf (Portable Document Format; Adobe Acrobat)
  • .doc, .docx (Microsoft Word Document)
  • .ppt, .pptx, .pps, .ppsx (Microsoft PowerPoint Presentation)
  • .odt (OpenDocument Text Document)
  • .xls, .xlsx (Microsoft Excel Document)

Audio

  • .mp3
  • .m4a
  • .ogg
  • .wav

Video

  • .mp4, .m4v (MPEG-4)
  • .mov (QuickTime)
  • .wmv (Windows Media Video)
  • .avi
  • .mpg
  • .ogv (Ogg)
  • .3gp (3GPP)
  • .3g2 (3GPP2)
However, you can extend this feature and add new file types to suit your needs.  Consider a graphics resources site where you want the ability to upload and store Adobe Illustrator Files (*.AI, *.EPS, etc).  The answer lies in the functions.php file.  This file is found in your theme folder and allows you to add, remove and modify the normal functions of the core WordPress.  This file is very powerful, so we recommend making a local backup before modifying it so you can undo any changes if needed.
  • First, locate your functions.php file in your active theme folder.  Generally, it will be found in the folder: /wp-content/themes/your-active-theme/functions.php.
  • Open the functions.php in a text or code editor.
  • Look up the mime type of the file support you want to add. This is very important, be sure to use the correct one.
  • Add the code below to your functions.php
  • Save changes and upload to your active theme folder, overwriting the original.
// Added to extend allowed files types in Media upload
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {

// Add *.EPS files to Media upload
$existing_mimes['eps'] = 'application/postscript';

// Add *.AI files to Media upload
$existing_mimes['ai'] = 'application/postscript';

return $existing_mimes;
}
A Couple of Notes:
  • If you add the code above to the end of your functions.php, be sure NOT to add any trailing blank lines (this is true of any modification of your functions.php file).
  • Obviously, you will not get automatically generated thumbnail images of additional files types so you may wish to add intuitive names using the Alternative Text and Title fields in the Media upload form.
  • Changes to the functions.php file only affect that single theme. If you change themes, you’ll have to modify your new functions.php file.
Need help implementing this tip in your WordPress site? Contact us for our professional services.  We can also provide support & expertise in convenient “blocks” to suit your short and long term needs.

Categories:

Related Articles on Similar Topics:

18 Responses to “Add Additional File Types to WordPress Media Library”

  1. Callie says:

    Thanks very much – this worked so I could upload an .ai file when I needed to.

  2. deddyika says:

    thanks

    it works… awesome

  3. Well, I’ve tried this using WordPress 3.4.1, and it breaks the site completely and generates a Server Error 500 message.

    I added the whole of the suggested code at the end of a copy of the functions.php in my Child Theme folder. I was careful to have no trailing spaces at the end.

    This isn’t quite what the topic suggests, but seems to follow the guidelines for making changes via Child Themes, rather than replacing the original (twentyeleven) theme functions.php file.

    Does this method not work with WP 3.x?

    Tx if you can help find an alternative.

    JohnMcC, Webmaster, Abbey Theatre St Albans

    • OOPS – I see the problem now.

      I did the same for the functions.php file as for the other theme files, copied the whole of the file, then added the code at the end.

      THAT’S WRONG for the functions.php file. You just include the code to want to ADD.

      Now I’ve done that, changing the file and mime types to what I want to use, it works

      Sorry for mistaken post

  4. A further apology – I mistyped our website address in my haste entering it in earlier posts. It should be

    http://www.abbeytheatre.org.uk – I missed out an ‘a’

    John McC

  5. Grant says:

    Just wanted to say thanks for this snippet. Just what I needed to upload eps files.

    This does work on WP 3.5.1.

  6. Michel Guillaume says:

    Well explained, thank you.
    Now, once you want to “Insert into post”, the corresponding file name comes with surrounding code. How can I customize this?

    • Hi Michel. After uploading the file to your Media library, but before you click “Insert into post”, you can change the “Title” field in the Attachment Details section. If you’ve already inserted the file/link into a post, you can click the Text tab (next to View) in the WordPress post/page editor and change the linked text between the hyperlink tags (a href). Hope that helps. Good luck!

  7. ETS 2 Mods says:

    What if I want to remove files-types from default list? Let’s say I want all admins to be able to upload only .jpg files, is it possible?

  8. Ternyata ada caranya !
    Oh, there’s A Way to do it !

    Terima Kasih telah membaginya :)
    Thanks for sharing :)

  9. Alex Nartey says:

    Hi,

    Admired is a great theme and am loving it.
    I want to create a child theme but would like to know if its possible to
    copy the whole folder of parent theme(Admired) and make some personal changes.

    Thanks for the good work.

  10. christian says:

    I changed the code and can upload .EPS file (logo), But the logo doesn’t show. It stays blank.. any ideas?
    (The JPG logo shows normal)

    • Sorry I wasn’t more clear, Christian. Even though you can upload other file types, it doesn’t mean the web browser will render them (like EPS). You will still be limited by the browser’s technical abilities. This tip is usually used so that webmaster can provide downloadable files to their users.

  11. Hmm, does adding this code updates, all file upload type on wordpress Blog, or it allows just some certain file

Leave a Reply

Subscribe

All Topics ()
Featured (39)
General News ()
Plugins (14)
Themes (11)
Tips & Tricks ()


 

Follow It's WordPress on Facebook Follow It's WordPress on Facebook Follow It's WordPress on Facebook Follow It's WordPress on Facebook