Limit authors and contributors to 2 MB uploads while administrators keep the server's full limit.
add_filter( 'upload_size_limit', function ( int $bytes ): int {
if ( current_user_can( 'manage_options' ) ) {
return $bytes;
}
return min( $bytes, 2 * MB_IN_BYTES );
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Writers often upload photos straight from their camera at 10 MB or more. That fills your storage and slows pages. This snippet sets a lower limit for everyone except administrators.
WordPress uses upload_size_limit to decide the largest file it accepts, and shows that limit in the uploader. The snippet returns 2 MB for non-administrators, or the server’s own limit if that’s already smaller.
upload_max_filesize and post_max_size in your PHP settings or ask your host.2 * MB_IN_BYTES to any size you like.Log in as an author and open Media → Add New. The “Maximum upload file size” should say 2 MB.