Rename wp-content Folder and Uploads – WordPress |
X

Congrats, You are Subscribed to Receive Updates.

Rename wp-content Folder and Uploads – WordPress


1.Rename “wp-content” Directory :

Renaming of wp-content directory helps to hide your WordPress information from the hacker. You can rename your wp-content directory with your desired name. Here i will rename it as “public_files”.

By the following code will change the name of wp-content. First of all open your  wp-config.php from your WordPress root directory and find the following line.

require_once(ABSPATH . 'wp-settings.php');

And paste the following code above this line

define ( 'WP_CONTENT_FOLDER' , 'public_files' );

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

define( 'WP_CONTENT_URL' ,WP_SITEURL . WP_CONTENT_FOLDER);

And remember you need to rename you wp-content folder by using FTP or your C Panel . Here i renamed it as “public_files“. You can use your desired one.

rename-wp-content-and-uploads-folder

2. Rename “Uploads” Directory :

The same thing we have to do for uploads directory. By the way , we have two options to configure it.

i. define it on your wp-config.php file.

ii. write a small php function to change it dynamically.

i. Use wp-config.php :

Open your wp-config.php and find the following line.

require_once(ABSPATH . 'wp-settings.php');

 and paste the following line of code above the line.

//If you'd like it inside the wp-content folder, specify path like this:
define( 'UPLOADS', 'wp-content/'.'medias' );

//If you'd like it outside the wp-content folder, specify path like this:
define( 'UPLOADS', ''.'medias' );

//Custom upload path
define( 'UPLOADS', ''.'medias' );

  that’s it the changes.  Now your default uploads directory is changed accordingly.

ii. PHP code to change uploads directory:

Add the following code to your theme “functions.php”. It will change your uploads directory when the theme is activated.

function kv_custom_medias_dir( $pathdata ) {
	$subdir = '/medias'.$pathdata['subdir'];
	$pathdata['path'] = str_replace($pathdata['subdir'], $subdir, $pathdata['path']);
	$pathdata['url'] = str_replace($pathdata['subdir'], $subdir, $pathdata['url']);
	$pathdata['subdir'] = str_replace($pathdata['subdir'], $subdir, $pathdata['subdir']);
	return $pathdata;
}	

add_filter('upload_dir' , 'kv_custom_medias_dir');

Now you have done the changes. If you have any doubts and bug’s just drop a comment here.

Note:

Renaming of wp-content directory affects your installed theme and plugins. Several plugins use wp-content directly instead of functions to get the path name.

If you are interested to read more tutorials from kvcodes. Subscribe our newsletter and follow me on social sites which you like to follow.

commenter

About Mizanur Rahman

Comment Below

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

*

Current ye@r *

Menu

Sidebar