Blog

WordPress tweaks via wp-config.php file

Tags: wordpress

Published on: July 24, 2019 by Sheldon Moor

WordPress tweaks via wp-config.php file

Scenario:

wp-config.php file is located inside the root directory of the WordPress installation and it is created during the installation process. This file stores the database configuration of your WordPress. Here, we are going to look at some wp-config.php tweaks which become handy for troubleshooting various WordPress issues.

1. Adding Security Keys in WordPress

By default WordPress installation automatically adds security keys to your configuration file. If you feel someone may be accessing your website without proper authentication, you can then regenerate the security keys from https://api.wordpress.org/secret-key/1.1/salt/

define( 'AUTH_KEY', 'put your unique phrase here' );

define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );

define( 'LOGGED_IN_KEY', 'put your unique phrase here' );

define( 'NONCE_KEY', 'put your unique phrase here' );

define( 'AUTH_SALT', 'put your unique phrase here' );

define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );

define( 'LOGGED_IN_SALT', 'put your unique phrase here' );

define( 'NONCE_SALT', 'put your unique phrase here' );

2. Debugging in WordPress

In order to enable the debug mode, you will need to add this rule in your WordPress configuration file.

define( 'WP_DEBUG', true );

You can also turn on debugging while hiding the errors on your website and saving them in a log file instead. To do that, add the following lines to your configuration settings.

define( 'WP_DEBUG', true );

define( 'WP_DEBUG_LOG', true );

define( 'WP_DEBUG_DISPLAY', false );

This will create a debug.log file inside wp-content folder of your website and store all debugging errors and notices inside the log file.

3. Changing Site URL and Home URL

you can change the site URL and Home URL via wp-config.php file by adding the following lines:

define('WP_HOME', 'http://www.example.com');

define('WP_SITEURL', 'http://www.example.com');

Replace example.com with your own domain name.

4. Override File Permissions

define('FS_CHMOD_FILE', 0644);

define('FS_CHMOD_DIR', 0755);

5. Changing Post Revision Settings

Post revision feature allows you to undo changes to your posts and pages by reverting back to a previous version or an autosave. You can change the post revision settings by using the following code.

define('AUTOSAVE_INTERVAL', 120); // in seconds

Also, you can disable the post revisions feature by using the following code.

define( 'WP_POST_REVISIONS', false );

6. Changing WordPress Trash Settings

When a post is deleted it is stored on your website for the next 30 days as trash. After that time, WordPress delete them permanently. You can use the following code to change the number of days you want to keep the trash.

define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days

Also, you can disable this feature by adding the below code.

define('EMPTY_TRASH_DAYS', 0 );

7. Allow Automatic Database Repair

In order to enable this feature, you need to add the following line to your wp-config.php file.

define('WP_ALLOW_REPAIR', true);

After adding this, you need to visit the following URL to optimize and repair the WordPress database

http://example.com/wp-admin/maint/repair.php

Replace example.com with your own domain name.

8. Increasing PHP Memory Limit

You can increase the PHP memory limit through wp-config.php file by using the following code.

define('WP_MEMORY_LIMIT', '128M');

9. Moving wp-content Directory

Moving wp-content directory can help strengthen WordPress security. For this, you will need to add the following code to your wp-config.php file.

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );

define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');

define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );

define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');


Replace example.com with your own domain name.

10. Use Custom User Tables

WordPress saves all user data in the tables wp_users and wp_usermeta by default. By using the below code, you can specify the table where you want your user information stored.

define('CUSTOM_USER_TABLE', $table_prefix.'my_users');

define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');

11. Enable Multi-Site Network

You can enable the Multi-Site functionality by adding the following line to the wp-config.php file. 1

define('WP_ALLOW_MULTISITE', true);

12. Limiting Access to wp-config.php file

You can add the following code to your .htaccess file to limit access to the wp-config.php file.

# Protect wp-config.php

<Files wp-config.php>

order allow,deny

deny from all

</Files>

13. Changing the Default Theme

You can easily change the default theme by adding the below code to the wp-config.php file.

define('WP_DEFAULT_THEME', 'twentyeleven');

14. Disable the Theme and Plugin Editors

If you want to protect your plugin or theme files from editing by someone, you can turn off both editors using DISALLOW_FILE_EDIT as shown below:

define('DISALLOW_FILE_EDIT', true);

15. Change Uploads Folder Path

You can change the name of the “Uploads” folder to any name you want by using the following code.

define( 'UPLOADS', 'wp-content/folder' );

16. Allow unfiltered uploads for admins

define ('ALLOW_UNFILTERED_UPLOADS', true);

By default WordPress limit certain file types which you may upload and disallows the upload by giving a security warning. In such cases, you can use the above code to overcome this warning and upload the file.

17. Disable Cache and Cache Expiration

You can disable the cache by adding the below code to the wp-config.php file of the domain.

define( 'WP_CACHE' , false);

Also, you can use the below code to specify the cache expiration time.

define ( 'CACHE_EXPIRATION_TIME' , 3600);

 

wp-config.php file

Category : WordPress

Sheldon Moor

Sheldon Moor

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Get new updates

Categories

$0.000 items