Post

WP Config file cheatsheet

The WP Config file is like the DeathStar in Star Wars. It’s a pretty big player in galaxy Wp and also it’s a powerful file, which you can use for several different purposes. The following is a collection of use cases for our infamous WP Config file.

Here we demonstrate how you can use “the force” of the wp config file and utilise its power to configure your site.

Disable wp core auto updates

Hey, auto updates can sometimes take your site to the dark side. Meaning, if Wordpress core updates and there is a conflict with a plugin your site can go down.

1
define( 'WP_AUTO_UPDATE_CORE', false );

Output debug errors to debug.log

Its really helpful for improving your site health to see all the php warnings and god forbid, errors on your site. Notice the “display errors off” part. This is a great feature as you don’t want to frighten your audience by displaying php errors to them.

What you want is to output a log of the errors in a separate file. You can then use that file to inspect and correct each of the errors.

Using the below snippet the debug.log file will be generated automatically to the wp-content folder

1
2
3
4
5
6
ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true); // will produce a debug log file of all php errors in /wp-content/debug.Log file
define('WP_DEBUG_DISPLAY', false);

Increase memory

Increasing memory allocation via the wp-config.php file can be an effective technique for improving the performance of your WordPress site, especially in scenarios where the default memory limit is insufficient. You would typically implement this technique in the following use cases:

  1. Large WordPress Sites: If your site has a lot of content, plugins, or themes, it may require more memory to operate efficiently.
  2. Resource-Intensive Plugins or Themes: Some plugins or themes may require more memory to function properly, especially those performing complex operations or handling large datasets.
  3. Site Crashes or Errors: If your site frequently crashes or displays error messages related to memory exhaustion, increasing the memory limit can help mitigate these issues.
  4. Performance Optimization: Increasing memory allocation can improve the overall performance of your site by reducing the likelihood of out-of-memory errors and speeding up page load times.

To implement this technique, you would edit the wp-config.php file and add a line similar to the following:

1
define( 'WP_MEMORY_LIMIT', '256M' );

Replace '256M' with the desired memory limit, such as '512M' or '1024M' depending on your specific requirements. Make sure to test your site thoroughly after making this change to ensure compatibility and stability.

Define site url

Defining the site URL in the WordPress wp-config.php file is important for several reasons:

  1. Consistency: It ensures that the site URL remains consistent across all parts of the WordPress installation, preventing issues with links and redirects.
  2. Security: By explicitly defining the site URL, you can prevent unauthorized changes to the URL via the WordPress admin interface or other means.
  3. Performance: Directly specifying the site URL can improve performance by bypassing database queries to retrieve this information.
  4. Compatibility: It ensures compatibility with plugins and themes that rely on the site URL being defined in the wp-config.php file.

Overall, defining the site URL in the wp-config.php file helps maintain stability, security, and performance for your WordPress site.

1
2
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );

Set limit to page revisions

This will save help keep your database smaller in file size.

1
define('WP_POST_REVISIONS', 3);

Disable page revisions

This will save help keep your database smaller in file size.

1
define('WP_POST_REVISIONS', false);

Increase upload limit

1
2
3
4
@ini_set( 'upload_max_size' , '12M' );
@ini_set( 'post_max_size', '13M');
@ini_set( 'memory_limit', '15M' );

Secure file editing in WordPress admin

Add the following line to your wp-config.php to disable file editing from within the WordPress admin area:

1
define( 'DISALLOW_FILE_EDIT', true );
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.