How to rename your WordPress wp-content directory

How to rename your WordPress wp-content directory

If you have been working with WordPress, you probably already know that all assets like images, stylesheets, themes, and plugins in WordPress are by default, stored under the /wp-content/ directory. But, do you know that we can actually change this folder name into something else, and yet it will still work?

One of the advantages of renaming /wp-content/ is that your website will look less WordPress-ish, while others say that this could even make your site more secure.

In this post, we will show you how to do it.

Create a New Folder

In this example, we will rename the /wp-content/ folder to /assets/. Note that after renaming this folder, any activated plugin or theme will be deactivated and will not be listed in their respective pages, since WordPress cannot find them from the default location, wp-content.

Configure Modification

We need to make a few modifications to /wp-config.php, but, it is better to create a backup of this file before making any change. Just in case something wrong happen, we will be able to restore it with the backup.

First, add the following line before require_once(ABSPATH . 'wp-settings.php'); (usually located at the very bottom) to tell WordPress that the /wp-content/ has changed to /assets/.

define ( 'WP_CONTENT_FOLDERNAME', 'assets' );

Then, add this line below to direct WordPress to the new directory path.

define ( 'WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );

After adding the above line, WordPress will find and list the installed themes and plugins.

But, as you can seen in the theme screenshot (see below) the link remains broken.

To fix this issue, add this line to specify the new directory URL.

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

We are done. Now, all the plugins, themes, and any media that we upload will be stored in our new folder.

Must Note!

There are several plugins and themes that do not follow best practices. They specify /wp-content/ as the path and URLin their code, instead of defining them dynamically. In such cases, the plugins and themes may not function properly. Furthermore, this will also break links to images that already attached in your posts and that are stored in /wp-content/.

So, this modification should be taken with caution and, it is better done when you just starting your website. Otherwise, it could ruin your website entirely, and there will be tons of things you have to fix.

Author source

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.