# Limit the Maximum Upload Size

> Caps the size of files that can be uploaded through WordPress at 8 MB, even if the server allows more.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: media, uploads, limits
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/limit-upload-size/

## Code

```php
add_filter( 'upload_size_limit', function ( $bytes ) {
    return min( (int) $bytes, 8 * MB_IN_BYTES );
} );
```

## Notes

This can only lower the server limit, not raise it.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit the Maximum Upload Size" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
