Add Additional File Types to WordPress Media Library

19 Comments

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.

I'm the front-man of It's WordPress. I come from a diverse array of backgrounds, enjoying the opportunity to expand my knowledge base and skill set by re-inventing myself. I enjoy environments that focus on emerging information, technology and concepts. I put on the technical hat in my early 20s and never really looked back. I'm love technology and the internet, as well as the outdoors and avidly hike, kayak and camp every chance I get.

About Us

We can take you from concept, through design, development and deployment in one seamless process. Whether you choose a self-managed web site or need a continuing support relationship; we've got you covered.

Click to edit this heading

Request Consulation

Ready to transform your vision into a reality? Just looking to see what it takes to get the ball rolling. Tell us about your project and we can help. No spam. No obligation. Just answers.

More from our blog

See all posts
19 Comments
  1. Reply

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

    • Reply

      Hi Neon, sorry for the delay in replying. You will have to add the mime type for each different file type you want to support, but you do not have to add the entire code block in its entirety each time. Does that make sense?

  2. Reply

    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)

    • Reply

      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.

    • Alex Nartey
    • September 18, 2013
    Reply

    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.

  3. Reply

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

    Terima Kasih telah membaginya 🙂
    Thanks for sharing 🙂

  4. Reply

    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?

  5. Pingback: Adding CBZ format to WordPress - eBabble

    • Michel Guillaume
    • April 12, 2013
    Reply

    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?

    • Reply

      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!

    • Grant
    • March 6, 2013
    Reply

    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. 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

  7. 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

      • Reply

        Hi John. Glad you got the code snippet working. Nice troubleshooting! Best of luck with your web site.

  8. Reply

    thanks

    it works… awesome

  9. Reply

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.