Yogesh Chauhan's Blog

Moving folders in WordPress using code

in WordPress on December 30, 2021

You need to make the following changes into wp-config.php file.

We can use PHP dirname to get a parent directory’s path.

This will return the directory of current included file:


dirname(__FILE__);

How to move wp-content folder?

wp-content directory holds themes, plugins, and uploads

Use this code to WP_CONTENT_DIR to the full local path of wp-content directory (without the trailing slash):


define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/blog/wp-content' );

Use this code to WP_CONTENT_DIR to the full URL of wp-content directory (without the trailing slash):


define( 'WP_CONTENT_URL', 'https://yogeshchauhan.com/blog/wp-content' );

How to move the plugins folder?

Use this code to WP_PLUGIN_DIR to the full local path of plugins directory (without the trailing slash):


define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/blog/wp-content/plugins' );

Use this code in case you have compatibility issues:


define( 'PLUGINDIR', dirname(__FILE__) . '/blog/wp-content/plugins' );

Use this code to WP_PLUGIN_DIR to the full URI of plugins directory (without the trailing slash):


define( 'WP_PLUGIN_URL', 'http://yogeshchauhan.com/blog/wp-content/plugins' );

How to move the themes folder?

You won’t be able to move the themes folder since themes directory path is hardcoded relative to the wp-content folder:


$theme_root = WP_CONTENT_DIR . '/themes'; 

You have an option to register additional theme directories via register_theme_directory WordPress function.

How to move the uploads folder?

Use this code to move the uploads folder:


define( 'UPLOADS', 'blog/wp-content/uploads' );

No need to add a leading slash in the uploads path address since it is always relative to ABSPATH.

Uploads folder path can not be absolute.


Most Read

#1 How to add Read More Read Less Button using JavaScript? #2 How to check if radio button is checked or not using JavaScript? #3 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to compress images with gulp in WordPress?WordPressHow to add and remove list items using JavaScript?JavaScriptHow to select an element using its ID without the high specificity of the ID selector?CSSThe difference between isFinite() method and isFinite() function in JavaScriptJavaScriptWhat are Class Constants in PHP?PHPUse eq() method in jQueryjQuery