Skip to content

Modify the /uploads path structure

The default path structure for URLs of files uploaded to a site’s WordPress Media Library is /wp-content/uploads/YYYY/MM/. An uploaded file will have a URL structure similar to: https://example.com/wp-content/uploads/2023/09/file.jpg

This default structure can be overridden with the pre_option_uploads_use_yearmonth_folders filter, added to a theme’s functions.php file.

This code example demonstrates omitting the year (YYYY/) and month (MM/) path segments from the directory structure for uploaded files:

/themes/example-theme/functions.php
add_filter( 'pre_option_uploads_use_yearmonth_folders', function() { return '0'; }, 9999 );

After deploying the above code example to an environment, all new files uploaded to the site’s Media Library will have a URL structure similar to:

  • /wp-content/uploads/{Filename} for WordPress single sites and for the main site (ID 1) of a WordPress multisite.
  • /wp-content/uploads/sites/{Site_ID}/{Filename} for a network site on a WordPress multisite.

The directory structure of all media files that were uploaded prior to adding the filter will remain unchanged. Those files will continue to be available at the default /wp-content/uploads/YYYY/MM/ structure.

Additional structures

Other custom directory structures can be applied by combining the pre_option_uploads_use_yearmonth_folders filter with the upload_dir hook.

Last updated: December 22, 2023

Relevant to

  • WordPress