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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.