Excellent software and practical tutorials
In WordPress, wp-contentThis is the default user content directory. All plugins and themes are also uploaded to the wp-content/plugins and wp-content/theme directories, respectively. Perhaps you didn't know this, but WordPress allows users to relocate, move, or rename wp-content to any directory they desire! To set up the content and plugin directories for WordPress, edit the wp-config.php file. Insert the following code into the file. The following four constants redefine the content and plugin paths for WordPress.
/** Set the wp-content directory path**/
define('WP_CONTENT_DIR', '/path/to/custom/wp-content');
define('WP_CONTENT_URL', 'url/to/custom/wp-content');
/** Set plugin directory path**/
define( 'WP_PLUGIN_DIR', '/path/to/custom/plugins' );
define( 'WP_PLUGIN_URL', 'url/to/custom/plugins' );
For example:
define( 'WP_CONTENT_DIR', '/home/uzbox/public_html/user_content' );
define( 'WP_CONTENT_URL', 'https://uzbox.com/user_content' );
define( 'WP_PLUGIN_DIR', '/home/uzbox/public_html/plugins' );
define( 'WP_PLUGIN_URL', 'https://uzbox.com/plugins' );
Note: The constants WP_CONTENT_DIR and WP_PLUGIN_DIR are used to specify the system path for content and plugins, which means you can no longer use generic directory names like wp-content. This directory cannot be specified arbitrarily; it must be a location accessible by the web server, so the ideal location must be within the website root directory or a subdirectory.
Use PHP's global variables $_SERVER['DOCUMENT_ROOT'] and $_SERVER['SERVER_NAME'] to construct a path relative to the root directory.
For example:
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/user_content' );
define( 'WP_CONTENT_URL', $_SERVER['SERVER_NAME'] . '/user_content' );
The constants WP_CONTENT_URL and WP_PLUGIN_URL specify a base URL for a custom directory (without the "/") so that both the content and plugin directories are accessible normally.
It is possible to completely remove the wp-content directory. You can simply specify the content directory as the root directory of your website. For example:
define( 'WP_CONTENT_DIR', '/home/uzbox/' );
define( 'WP_CONTENT_URL', 'https://uzbox.com/' );
define( 'WP_PLUGIN_DIR', '/home/uzbox/plugins' );
define( 'WP_PLUGIN_URL', 'https://uzbox.com/plugins' );
In this case, all themes, plugins, and upload directories will be exposed directly under the root domain. https://uzbox.com/themes, https://uzbox.com/plugins, https://uzbox.com/uploads
Using WP_PLUGIN_DIR and WP_PLUGIN_URL, users can change the plugin directory name. For example, use "CHAJIAN" or "pi." Since the plugin directory can be configured to be located outside the content directory, you can place it outside the content directory or still within the content directory. However, once you change the wp-content directory, it will no longer make sense to specify the plugin directory within the wp-content directory. If you want to maintain the WordPress directory structure, the plugin directory should also be placed in the content directory.
After changing the content directory, users may need to change the upload directory of WordPress to avoid some path problems. For this part, please refer to "How to change the upload directory in WordPress". If you have changed the path and name of the wp-content directory in the website, it is extremely important to move the current themes, plugins and upload directories (if the names of the latter two have not changed) to the appropriate paths to ensure that the WordPress program can work properly. In addition, all addresses pointing to images, videos, media and other files should be corrected to a correct path. These changes are not limited to articles and pages, and we can save them using the options of the theme or plugin.
WordPress doesn't directly provide a way to rename or change the location of theme files. However, WordPress provides a function called register_theme_directory() to register a directory for theme files, essentially an additional theme folder. To register an additional theme directory, create a plugin called "Extended Theme Directory." Then upload it to your plugin folder and activate it.
The code is as follows:
/*
Plugin Name: Extended Theme Directory
Plugin URI: https://uzbox.com/
Description: Re-register a directory to place the theme
Version: 1
Author: lyblog
Author URI: https://uzbox.com/
*/
register_theme_directory('/path/to/themes/directory');
Remember to replace the directory above with a system directory pointing to your theme, or a folder containing WP_CONTENT_DIR or WP_PLUGIN_DIR. If you want to add a theme directory to the content directory, you can use constant links to achieve relative directories.
register_theme_directory(WP_CONTENT_DIR . '/themes');
Finally, and most importantly, when the wp-content folder is customized, some themes or plugins may not recognize it correctly. Therefore, try not to customize the directory to avoid crashing the site. These problems may be caused by the developer not following the built-in functions of WordPress to obtain the directory. For this type of problem, try to use Apache's URL rewrite module (or similar methods for other types of servers) to redirect the directory. This should rewrite all links to the wp-content directory to a new location. For example, you can add the following code to your .htaccess file and restart the server:
RewriteRule (.*)(wp-content)(.*) $1content$3 [NC,R,L]
or
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/wp-content(/*)
RewriteRule ^wp-content/(.*)$ /content/$1 [L, NC]
In the above code, all requests to "/wp-content" are redirected to the "/content" directory. The above URL rewriting conditions and rules are just examples and may not apply to your server environment. You should configure them according to your server. If your theme or plugins use paths to call PHP files, URL rewriting will not work.