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

    restrict-uploads-to-specified-file-types-only-jpg-gif-png

    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 ) ( click code to copy )

    wordpress snippet : PHP

    <>
    add_filter('upload_mimes','restrict_mime');
    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,