How to Rename Your WordPress WP-Content Directory

By . Filed in Wordpress

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.

Config 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', 'http://' . $_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 url in 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:

Thoriq has been dabbling in Web Design for 5 years and appreciates the giving nature of the web design community at large. He loves trying new things in CSS3 and HTML5. Apart from writing on hongkiat.com he also maintains creatiface.

Advertisement