wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Restrict uploads to specified file types only, jpg, gif

wordpress snippet

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 )
snippet :  PHPcopy
function restrict_mime($mimes) { 
$mimes = array( 
                'jpg|jpeg|jpe' => 'image/jpeg', 
                'gif' => 'image/gif', 
return $mimes;

Did you like this post? If so please share it with your friends. Thanks!

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