• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Snippets » WordPress Snippets » Add Custom Media Type Filters in WordPress Media Library

Add Custom Media Type Filters in WordPress Media Library

Posted on July 12, 2012 by Renji | Short URL: http://sumtips.com/?p=7205

By default only three filters – Images, Video, and Audio – are supported in the WordPress Media Library. If you upload other file types on your blog, following code snippet will allow you to add filters for those as well:

function custom_mime_types( $post_mime_types ) {
        $post_mime_types['application/msword'] = array( __( 'DOCs' ), __( 'Manage DOCs' ), _n_noop( 'DOC <span class="count">(%s)</span>', 'DOC <span class="count">(%s)</span>' ) );
        $post_mime_types['application/vnd.ms-excel'] = array( __( 'XLSs' ), __( 'Manage XLSs' ), _n_noop( 'XLS <span class="count">(%s)</span>', 'XLSs <span class="count">(%s)</span>' ) );
        $post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
        $post_mime_types['application/zip'] = array( __( 'ZIPs' ), __( 'Manage ZIPs' ), _n_noop( 'ZIP <span class="count">(%s)</span>', 'ZIPs <span class="count">(%s)</span>' ) );
		
        return $post_mime_types;
}
add_filter( 'post_mime_types', 'custom_mime_types' );

Custom Media Type

Just drop the code in your theme’s functions.php file. The code as it is will add filters for DOCX, XLS, PDF, and ZIP files.

WordPress supports a whole lot more mime types, and you can easily add those to the above code. To see the complete list of supported mime types, open wp-includes/functions.php file and search for get_allowed_mime_types. (via Wptuts+)


Tweet

Related posts:

  • Add Pages, Custom Post Types in WordPress Site Feed
  • Change "Enter title here" text for Post, Page and Custom Post Type in WordPress
  • Add, Disable & Use Custom Image Sizes in WordPress 3.3 Media Uploader
  • Customize WordPress HTML Editor With Custom Quicktag Buttons
  • Customize WordPress TinyMCE Editor With Custom Buttons
Categories: WordPress Snippets
Remove Website and Email Fields from WordPress Comment form
Get Links to Next and Previous Posts in WordPress Post Editor

  • Get Updates via Email

  • Recent Posts

    • Gmail for Android: Delete Message Instead of Archive from Notification
    • AlarMe: A Weather-based Alarm Clock for Android Devices
    • Hide any Term, Phrase, Person, or Hashtag from Twitter & Facebook Feed
    • How to Enable or Disable Tabs in Gmail Inbox
    • Install Google Chrome Extensions in Opera directly from Web Store
    • List of Web Services Supporting Two-Factor Authentication
  • Random Posts

    • Google Chrome 8 Gets GPU Acceleration, Cloud Printing
    • 6 Useful Hacks to Enhance Windows Context Menu
    • Get Quick Access to All Hidden ‘About:’ Pages In Chrome
    • Activate Do Not Track on All Browsers
    • Google Testing New AdSense Beta Interface
    • Move Minimize, Maximize & Close Buttons to The Left in Ubuntu
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy