# Default Upload Limits for Contact Form 7 File Fields

> Gives every Contact Form 7 file field a safe default list of allowed file types and a maximum size, unless the field already sets its own.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, uploads, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-default-upload-limits/

## Code

```php
$wpide_cf7_upload_types = 'pdf|doc|docx|jpg|jpeg|png'; // Allowed extensions, separated by |.
$wpide_cf7_upload_limit = '5mb';                       // Maximum size per file (kb or mb).

add_filter( 'wpcf7_form_tag', function ( $tag ) use ( $wpide_cf7_upload_types, $wpide_cf7_upload_limit ) {
    if ( empty( $tag->basetype ) || 'file' !== $tag->basetype ) {
        return $tag;
    }

    $options = (array) $tag->options;

    if ( ! $tag->has_option( 'filetypes' ) ) {
        $options[] = 'filetypes:' . $wpide_cf7_upload_types;
    }
    if ( ! $tag->has_option( 'limit' ) ) {
        $options[] = 'limit:' . $wpide_cf7_upload_limit;
    }

    $tag->options = $options;

    return $tag;
} );
```

## Notes

Fields with their own filetypes: or limit: options keep them; the server's upload_max_filesize must also allow the size.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Default Upload Limits for Contact Form 7 File Fields" 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/
