X

Add File Type Category Within the Media Library

Snippets by IsItWP

Adding this snippet to the functions.php of your wordpress theme will add a new file type category within the media library for application/x-shockwave-flash mime type. This is a great snippet when you have a lot of files so that you can sort by category.

function modify_post_mime_types($post_mime_types) {
    $post_mime_types['application/x-shockwave-flash'] = array(__(  'Flash (%s)', 'Flash (%s)'),__(  'Flash (%s)', 'Flash (%s)'), _n_noop( 'Flash (%s)', 'Flash (%s)'));
    return $post_mime_types;
}
add_filter('post_mime_types', 'modify_post_mime_types');

Comments   Leave a Reply

  1. This is a very helpful snipp…but it doesn’t seem to work for me. The dropdown simply adds ‘mimeframe’ to the list. I recently added a plugin to a client’s site for this functionality, but would love to just have it in functions.php. Is the code right?

    I’ve used a bunch of your other snipps, by the way…so I know how they work. Thanks! =)

    1. just updated the snippet should work for you now, it was a little out of date. It was setup to work without the dropdown / select menu. Let me know if you have any issues. Keep in mind that you would need to support the upload of flash, since it will only display the item within the menu once you have uploaded a file of that type.

      1. Wow…thanks!

        That added “Flash (%s)”. =)

        1. Strange I just tested in within 4.2.4 should work. %s should change the total number of files. To support a file type you would need to do this,

          http://wpsnipp.com/index.php/functions-php/add-support-svg-inside-wordpress-media-uploader/

          Although this is for svg the idea is the same, then wordpress will let you upload swf

          1. I see. I misunderstood. I thought this would just list (and sort) the different file types in the Library. It sounds like you were just adding Flash to the list, and if Flash is enabled they’ll show up.

            I can then edit this to show whatever file types I want…is that the idea?

          2. ya, this just ads a new file type to the list, because normally if you enabled swf in wordpress it would upload them but you could not filter them. This will add the type to the menu so you can also sort. However you only see the option once a file has been uploaded.

          3. I’m grateful for your helpful and speedy responses. The current code gives me the white screen of death. =) It looks valid to me, but I’m kind of a script kiddie when it comes to hooks and filters.

          4. that it should not do, even if its broken you would get an error not a white screen. Normally that can be attributed to something else, like a missing ?> or space at the end of the file.

          5. Agreed. Of course, I tried it about a dozen times. =)

            I tried it again just now, copying and pasting…no spaces after it. It’s the last thing in my file, which I’ve been adding snipps to and testing all morning. It’s just this one that gives me the WSOD. WP is up to date, btw.

            Thanks anyway, Kevin…this is an awesome website!

          6. if you would like send me a quick email via the contact form and ill send a reply when you send email me a copy of your functions.php file I can take a look see if its my fault or something simple so we can get things going for you. If you are cool with that,

          7. Cool with it? I’m amazed by your generosity. Message sent. Thanks!

      2. Wait…I assumed this would check the file types. Would it work for my filetypes if I add them to the array?

  2. Cor van Noorloos June 11, 2011 at 3:26 pm

    Hello Kevin,

    I only recently came across this site, and I have to admit, I really like it (:

    As this is the latest snippet I hope it’s OK to add this request here.
    As most snippets are quite specific, would it be possible for you to add beside the post thumbnail in each post a somewhat larger and more specific image (read screenshot) on what the topic exactly is about?

    It might will help more people here to grasp on what exactly the snippet is about.

    Best regards,

    Cor

    1. Hey glad to hear you like the website and the idea you have is a good one, Ill have to think about exactly how I would add the feature. Ill have to start adding the feature to all the new posts and slowly add to all the existing posts after that. Thanks for the feedback always nice to hear!

      1. Hi Kevin! I’ve seen you took Cor’s idea into consideration and it’s indeed a great idea! So maybe you could add an example screenshot for this code as well since I don’t get what it does 🙂

        Thanks!

        1. Hi Matthew,
          I have been adding them to all of the new appropriate snippets and older snippets but have not got to everything yet since I have over 430 snippets. In regards to this snippet within the media library you have selections at the top for all() images() unattached() this will let you add a new options to filter by file type in this sample .swf flash file.

        2. Ok I get it, thanks a lot Kevin 🙂

Add a Comment Cancel reply

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!