Home / admin / Add file type category within the media library
  • How to Add file type category within the media library

    add-file-type-category-within-the-media-library

    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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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');
    

    ( WordPress codex functions, hooks, in this snippet. )

    add_filter, __, _n,
  • Cor van Noorloos

    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

    • 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!

      • MatthewJ

        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!

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

        • MatthewJ

          Ok I get it, thanks a lot Kevin :)

  • tonyscialdone

    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! =)

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

      • tonyscialdone

        Wow…thanks!

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

        • 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

          • tonyscialdone

            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?

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

          • tonyscialdone

            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.

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

          • tonyscialdone

            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!

          • 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,

          • tonyscialdone

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

      • tonyscialdone

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