Media PHP Beginner

Keep All Uploads in One Folder

Stop WordPress sorting uploads into year and month folders, so new files go straight into /wp-content/uploads/.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 1 lines
add_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_zero' );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

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.

By default, uploads go into folders like /uploads/2026/11/. Some people prefer shorter URLs and one folder, for example on small sites with only a few hundred files. This snippet turns the date folders off.

How it works

The uploads_use_yearmonth_folders setting controls date folders. The pre_option_ filter returns 0 before WordPress reads the setting, so new uploads go into the main uploads folder.

Things to watch

  • Existing files stay where they are and keep their URLs.
  • Thousands of files in one folder can make some servers and FTP clients slow. Keep date folders on large sites.
  • File names must be unique in one folder, so WordPress adds numbers more often.

How to test it

Upload a file and check its URL. It should be /wp-content/uploads/filename.jpg with no year or month.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only