For version control purpose, our client has a WordPress app with directory structure like this:
.
|_____app
| |_____themes
| |_____plugins
| |_____uploads
|_____index.php
|_____WordPress
|_____wp-config.php
In wp-config.php
:
define('WP_CONTENT_DIR', __DIR__ . '/app');
define('WP_CONTENT_URL', WP_HOME . '/app');
Now, she want to rename all default WordPress folders in app directory.
With plugins
and themes
we can do it easily by using WP_PLUGIN_DIR
and register_theme_directory(). But, somehow, it’s not easy to rename uploads
folder.
I have tried many modifications with UPLOADS
constant, but it can’t help because custom uploads folder is always created inside WordPress
directory.
Are there any ways to workaround this problem?
2 s
After digging around, I ended up with using upload_dir
filter.
Here is what I tried in functions.php
to change uploads
to media
. Hope it can help someone too 🙂
add_filter('upload_dir', function($uploads)
{
$custom = [];
foreach ($uploads as $key => $value) {
if ( false !== strpos($value, '/app/uploads') ) {
$custom[$key] = str_replace('/app/uploads', '/app/media', $value);
} else {
$custom[$key] = $value;
}
}
return $custom;
});
Many thanks to @gmazzap for the guidelines and the suggestion about upload_dir
filter!