August 12, 2021

How to Rename Your WordPress WP-Content Directory in WordPress


If you're familiar with the Wordpress engine, you're aware that all site material, including themes, styles, plugins, and images, is saved by default in the wp-content directory. But did you know that you may rename this directory (folder) to whatever else and it would still work?

Changing engine settings

We'll rename the wp-content directory to assets, for example. Remember that after that, all plugins and themes will be disabled and will no longer appear in the control panel's appropriate areas. The search engine will be unable to locate them. It's important to make a few changes to the wp-config file in order for WordPress to remember where its default directory is again.Just in case, build a backup before making any changes so that you can restore the file to its former condition if something goes wrong.

So, after you've opened the file, look for the line require once (ABSPATH. 'Wp-settings.php') and add the following code after it (it's generally the last line):

define ( 'WP_CONTENT_FOLDERNAME' , 'assets' ) ; define ( 'WP_CONTENT_DIR' , ABSPATH . WP_CONTENT_FOLDERNAME ) ;

We've given wp-content a new name here. After saving and returning to your dashboard, you'll notice that all of your plugins and themes have been restored. The path to photos or other uploaded files must now be changed. Add two more lines to the same file to accomplish this:

define ( 'WP_SITEURL' , 'http: //' . $ _SERVER [ 'HTTP_HOST' ] . '/' ) ; define ( 'WP_CONTENT_URL' , WP_SITEURL . WP_CONTENT_FOLDERNAME ) ;

That is all there is to it. Wp-content is no longer present, the path in the settings has been changed to assets, and all files are now automatically imported into the new directory.

Final Thoughts

Despite the method's simplicity, there is an issue that you may encounter if you follow the steps above. It stems from the fact that some plugin and theme developers break certain conventions during development (for example, instead of utilising a static variable, they hard-code the root directory for files), causing their "crafts" to fail.This problem has only one solution: delve into the code, find the error, and repair it.

Read More →