Title: WordPress Gallery Upload Limit
Last modified: August 21, 2016

---

# WordPress Gallery Upload Limit

 *  [alex05](https://wordpress.org/support/users/alex05/)
 * (@alex05)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/wordpress-gallery-upload-limit/)
 * I’m trying to limit the amount of files a user can upload through the wp gallery,
   and i’ve found the following filter
 *     ```
       add_filter('wp_handle_upload_prefilter', 'yoursite_wp_handle_upload_prefilter');
       function yoursite_wp_handle_upload_prefilter($file) {
         list($category,$type) = explode('/',$file['type']);
         if ('image'!=$category || !in_array($type,array('jpg','jpeg','gif','png'))) {
           $file['error'] = "Sorry, you can only upload a .GIF, a .JPG, or a .PNG image file.";
         } else if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) {
           if (count(get_posts("post_type=attachment&post_parent={$post_id}"))>0)
             $file['error'] = "Sorry, you cannot upload more than one (1) image.";
         }
         return $file;
       }
       ```
   
 * However this filter works only on the current post, what i’m trying to achieve
   is to limit the upload only on that instance when the user opens the uploader,
   is it possible?

The topic ‘WordPress Gallery Upload Limit’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [alex05](https://wordpress.org/support/users/alex05/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/wordpress-gallery-upload-limit/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
