15 useful tips and tricks for wp-config

This file, wp-config.php, is important for the functionality of the whole WordPress site. That file contains data about the database, database user, database user password and other settings. It can be used for security and better performance of the website.

Where is the wp-config.php?

This file is in the root folder of your site. This is not the root folder of your hosting (server or hosting package), so pay attention to look in the root folder of your website. If you are on the cPanel, that is /public_html folder.

For the first time, if you are on the way to install WordPress manually, you cannot find this file by this name. The installation name od this file is wp-config.sample.php and here you can enter database information and save it as wp-config.php file name.

Note: Before you start, please, create a backup of your wp-config.php file.

1. Enable debug in WordPress

You can debug problems is WordPress if you enable this option. You can do that if you paste the following text in the wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
//define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );

This way, you can start debugging and logging all the errors from your WordPress site. The log file will be placed into /wp-content directory

2. Change your WordPress URL

You can change the URL of your website with the following code:

define('WP_SITEURL', 'http://www.your-domain.rs');
define('WP_HOME', 'http://www.your-domain.rs');

This can be useful if you migrate your site to the new URL because it overrides defined values in the wp-options database table.

Another way to do the same is to use the SERVER variable to set dynamic values:

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

3. Increase/decrease PHP memory limit

PHP memory limit can be increased/decreased if you add the following into wp-config.php:

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

Instead of 64 enter the desired value in MB.

Note: This is overcom at Adriahost hosting so you can use PHP options in Select PHP version application in your cPanel: How to change PHP version from cPanel

4. Change Trash Box timing

By default, after the user deletes article, page or comment, that will be sent to Trash Box, and WordPress will delete that after 30 days. To change this timing, enter the following into wp-config.php:

define( 'EMPTY_TRASH_DAYS', 15 );

Replace 15 and define your timing in days. You can disable Trash Box if you write 0 (zero) instead of any other number.

5. Turn off automatic updates in WordPress

From version 3.7, WordPress has an automatic update for the core. You can disable this if you add the following into wp-config.php:


6. Revisions in WordPress – define your Autosave intervals

During the editing of articles in WordPress, revisions will be saved automatically. By default, a revision will be created every 60 seconds, and you can change that with this line:

define( 'AUTOSAVE_INTERVAL', 180 );

Number 180 from the line above is the number of seconds between every revision.

If you also put the following line into wp-config.php you can define the maximum number of revisions saved by the WordPress:

define('WP_POST_REVISIONS', 7);

You can also turn off the revisions in WordPress with the help of following code:

define('WP_POST_REVISIONS', false)

7. FTP/SSH credentials

Some of the hosting servers require FTP or SSH credentials for every update of WordPress. You can add credentials like this:

define('FS_METHOD', 'ftpext');
//absolute path to root installation directory
define('FTP_BASE', '/path/to/wordpress/');
//absolute path to "wp-content" directory
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
//absolute path to "wp-plugins" directory
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
//absolute path to your SSH public key
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
//absolute path to your SSH private key
define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa');
//either your FTP or SSH username
define('FTP_USER', 'username');
//password for FTP_USER username
define('FTP_PASS', 'password');
//hostname:port combo for your SSH/FTP server
define('FTP_HOST', 'ftp.example.org:21');

You can also force direct method using the following:

define('FS_METHOD', 'direct');

8. Automatically repair the database

The site database, in some cases, can be corrupted. If you cannot enter into your WordPress Dashboard, you can add this line into you wp-config.php:

define('WP_ALLOW_REPAIR', true);

After that, go to the following address:


Once when the database is repaired, you can remove this line from the wp-config.php file.

9. Lock the edits of files from the back-end

To lock down any edit of plugin or theme files from the WordPress Dashboard, you can put the following code into the wp-config.php:


10. Turn on the WordPress theme

If you want to turn on the desired WordPress theme using only the wp-config.php file, you can put this line into this file:

define( 'WP_DEFAULT_THEME', 'name-of-the-theme-folder' );

11. Skip wp-content directory during the update

If you do not want to update wp-content files during the WordPress update you can do this easily if you add this line to your wp-config.php file:


12. Alow unfiltered upload for administrators

WordPress has some restrictions for some type of files. By default, you can’t upload any other type of files that is not image, video or document. If you want to upload more, you need to put this line into your wp-config.php file:


This line will remove the restrictions only for administrators.

13. Dynamic WPLANG for multilingual website

If you run a multilingual site and want the theme and administrative panel language to be translated, you can use the language detection code from the visitor’s Internet browser. Based on this data, WPLANG will also be defined.

First, create a wp-lang.php file, put the following text into that file and save it in the same folder of wp-config.php:

// start the session 
// if there's a "lang" parameter in the URL... 
if( isset( $_GET[ 'lang' ] ) ) { 
 // ...set a session variable named WPLANG based on the URL parameter... 
 $_SESSION[ 'WPLANG' ] = $_GET[ 'lang' ]; 
 // ...and define the WPLANG constant with the WPLANG session variable 
 define( 'WPLANG', $_SESSION[ 'WPLANG' ] ); 
// if there isn't a "lang" parameter in the URL... 
} else {
 // if the WPLANG session variable is already set...
 if( isset( $_SESSION[ 'WPLANG' ] ) ) {
 // ...define the WPLANG constant with the WPLANG session variable 
 define( 'WPLANG', $_SESSION[ 'WPLANG' ] ); 
 // if the WPLANG session variable isn't set...
 } else { 
 // set the WPLANG constant to your default language code is 
 define( 'WPLANG', 'sr_RS' ); 

Opet the wp-config.php and replace WPLANG row with the following:

require_once( dirname( __FILE__ ) . '/wp-lang.php' );

14. Move wp-config.php file from default location

You can move your wp-config.php file anywhere on the hosting, but you need to create wp-config.php in the default location with the following lines that will direct WordPress into the right location:

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
 define('ABSPATH', dirname(__FILE__) . '/');
/** Location of your WordPress configuration. */
require_once(ABSPATH . '../path/wp-config.php');

Don’t forget to replace /path/wp-config.php into your path to the wp-config.php file.

15. WordPress Multisite network – WPMU

If you want to start WordPress multisite, you also need to put the following code into your wp-config.php file:

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );

16. Turn on the native cache in WordPress

Native Cache can be activated if you write those lines into your configuration file:

define (‘WP_CACHE’, true);

It is mandatory to backup before editing

Always create a backup of any file you want to edit. You can create a backup file with a simple compress option from the cPanel File manager. So, if you make a mistake, you can easily resolve this problem with a backup file.


No comments yet.

Submit Comment