wp-config.php file – everything you need to know about this WordPress file

wp-config.php file – everything you need to know about this WordPress file

Table of Contents

Did you ever read an article with this title? wp-config.php file - everything you need to know about ? Keep on reading if not!One of the most crucial WordPress installation files is the configuration file. It resides in the root directory and contains constant definitions and PHP instructions that make WordPress work the way you want.The wp-config.php file stores data like database connection details, table prefix, paths to specific directories, and many settings related to specific features we will dive into in this post.

Custom Directory Locations

You can modify the location of various WordPress folders from the config file. This could be useful if you want to:
  • Migrating from a previous system to a site with a similar folder structure
  • Keeping things secure by not relying on a default structure
  • Removing clutter from the root directory
  • Moving the WP-Content folder
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/site/wp-content' ); 
define( 'WP_CONTENT_URL', 'http://example.com/site/wp-content' );
The first constant sets the full directory path, and the second sets the new directory URL.

Moving the plugins folder

In the same manner, you can move the plugins folder of your WordPress site
define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/wp-content/folder/plugins' );
define( 'WP_PLUGIN_URL', 'http://example.com/wp-content/folder/plugins' );
When done, arrange the folders according to your modifications and reload WordPress.

Debug Mode and Saving Queries

In some cases, you may be able to force WordPress to display errors and warnings for theme or plugin debugging purposes. You need to set the WP_DEBUG value to true to enable debugging:
define( 'WP_DEBUG', true );
As we mentioned earlier, you should disable the debug mode when working on a live site. Warnings and errors should never be displayed to site viewers, as this can provide valuable information to hackers.However, if you need to debug, you can force WordPress records information about errors and warning in a file, placed in a debug.log file, placed in /wp-content folder.To do so, you need to add these lines of code in the wp-config file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Modify The AutoSave Interval of WordPress

WordPress uses Ajax to save changes to posts as you edit them automatically. Increasing this setting will delay auto-saving, but lowering it will ensure you never lose changes. The default setting is 60 seconds.
define( 'AUTOSAVE_INTERVAL', 30 );
You can also disable the functionality if you want by adding this piece of code:
define( 'WP_POST_REVISIONS', false );

Prevent anyone from editing plugins/themes from inside the Admin Dashboard

This is useful if you are an agency or a freelancer and want to block your customers from messing with your work.
define( 'DISALLOW_FILE_EDIT', true );
However, there are a lot of other configurations that can be done in the wp-config.php file. If you read this article and have some questions about wp-config.php or about WordPress in general, please comment on this article, I'm 12/24 online as I'm working remotely for about 12 years now. I will really enjoy being able to help you out and this may be to update the article with new and interesting configs for wp-config.php. Cheers!

Table of Contents