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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #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
Ampersand (Parent Selector) in SCSS (Sass)SCSSHow to create a simple tab interaction using CSS?CSSHow to avoid element shift on border change while hovering in CSS?CSSCustom Post Type Template Files in WordPressWordPressHow to add recaptcha version 3 to PHP website?PHPinclude, include_once, require, require_once in PHPPHP