Home / admin / Restrict uploads to specified file types only, jpg, gif
  • How to Restrict uploads to specified file types only, jpg, gif


    Adding this snippet to the functions.php of your wordpress theme will allow you to restrict uploads to an array of specified mime types only. This sample only allows jpg and gif images, adding a new line for png eg: ‘png’ => ‘image/png’, would then allow png images.

    ( example screenshot )

    wordpress snippet : PHP

    function restrict_mime($mimes) { 
    $mimes = array( 
                    'jpg|jpeg|jpe' => 'image/jpeg', 
                    'gif' => 'image/gif', 
    return $mimes;

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

    upload_mimes, add_filter, wp,
  • http://twitter.com/RoneNeffect Rone Neffect

    How would you set restriction parameters for non-image file types like PDFs? Thanks!

    • http://wpsnipp.com Kevin Chard

      Hi Rone, you should be able to just add a new line after line 05

      ‘gif’ => ‘image/gif’,
      ‘pdf’ => ‘application/pdf’,

      that should do it just copy the line and paste it in.

      • http://twitter.com/RoneNeffect Rone Neffect

        Most excellent! Thanks Kevin!

        • http://wpsnipp.com Kevin Chard

          No problem anytime Rone,

  • Pingback: Restrict WordPress Users from Uploading Audio & Video Media...()