# Add the Date to Uploaded File Names

> Prefixes uploaded file names with the upload date, such as 2025-03-14-team-photo.jpg, so files sort chronologically on the server and in downloads.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: uploads, file-names, organization
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/media-date-prefix-file-names/

## Code

```php
// Date format used as the prefix.
$wpide_upload_date_format = 'Y-m-d';

add_filter( 'wp_handle_upload_prefilter', function ( $file ) use ( $wpide_upload_date_format ) {
    if ( preg_match( '/^\d{4}-?\d{2}-?\d{2}/', $file['name'] ) ) {
        return $file;
    }
    $file['name'] = wp_date( $wpide_upload_date_format ) . '-' . $file['name'];
    return $file;
}, 5 );
```

## Notes

Change $wpide_upload_date_format, for example to Ymd; files that already start with a date are left alone.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Add the Date to Uploaded File Names" 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/
