The Wordpress Configuration File
Posted 04th October, 2018
The wp-config.php file, which by default sits in the root folder of a Wordpress install, contains the core configuration for each and every Wordpress site.
- Like most online software, Wordpress has files and a database. These are linked together with the database configuration.
- Debug mode can be toggled on and off
- Key settings, such as website URLs, can be overridden.
Database Credentials
Database credentials can be found in every Wordpress wp-config.php file, in the following format:
define( 'DB_NAME', 'Your_database_name' );
define( 'DB_USER', 'The_username_for_your_database' );
define( 'DB_PASSWORD', 'Your_password' );
define( 'DB_HOST', 'Your_database_host' );
Changing any one of these lines will modify, and potentially break, your database connection.
In addition you will find a DB_PREFIX option. This is the prefix used on your database tables; most commonly set to wp_
.
Debug Mode
Debug mode can help diagnose the following issues:
- Locating a plugin issue
- Theme problems
- Deprecated functions
PHP errors, notices and warnings are logged, including notices generated off screen. Errors are logged to /wp-content/debug.log
.
You can enable Debug mode by updating the WP_DEBUG line to the following:
define( 'WP_DEBUG', 'true' );
Wordpress URLs
Wordpress has a main website URL which can be changed. This setting is stored in the database and can be configured in the Wordpress admin area.
However, you can override this setting in the wp-config.php file by adding the following lines:
define( 'WP_SITEURL', 'http://example.com/wordpress' );
define( 'WP_HOME', 'http://example.com/wordpress' );
Replace the URLs with your own domain.
Define custom directories
If you want to change the directory names of your wp_content, theme, media, or admin folders, you can do this with one line. This is often done for security - changing the default settings that Wordpress is set up with.
Different folders have different methods:
WP Content Directory
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '../custom/directory' );
Uploads folder
define( 'UPLOADS', 'wp-content/media' );
Theme root folder
$theme_root = WP_CONTENT_DIR . '/themes';
Automatic Updates
You can configure automatic updates of the WordPress core. Note that this would not update plugins or themes.
define( 'WP_AUTO_UPDATE_CORE', true );
Alternatively, you can completely disable all automatic updates as follows:
define( 'AUTOMATIC_UPDATER_DISABLED', true );