The WordPress configuration file is wp-config.php, where constants are defined and certain PHP instructions are given. This file should not be changed arbitrarily and it should be noted that the most appropriate place to add constants and functions is before the comment line:
/* That's all, stop editing! Happy publishing. */
If this file is reviewed, various sections can be seen, including the configuration of the database (database name, user, password, host, character encoding, character map order and prefix of the tables), which are given by the following data:
- DB_NAME: Name of the database
- DB_USER: Name of the user with permissions
- DB_PASSWORD: User access password with permissions
- DB_HOST: Host of the database, which is usually localhost
- DB_CHARSET: Default character map of the database. Normally utf8 is used
- DB_COLLATE: Character map order. It should not be indicated
- $table_prefix: Prefix that the tables of the database will take to distinguish them from other tables of other installations. It is convenient to use a prefix other than ‘wp_’ for security reasons
and the unique authentication keys:
- AUTH_KEY
- SECURE_AUTH_KEY
- LOGGED_IN_KEY
- NONCE_KEY
- AUTH_SALT
- SECURE_AUTH_SALT
- LOGGED_IN_SALT
- NONCE_SALT
which make the site more difficult to hack and break your security due to these random secret keys that are added to the access password.
Another data that is added is the debug mode constant, which is inactive by default, and that can be activated in the case of being in a development environment to see the warnings:
- WP_DEBUG, with the code
define('WP_DEBUG', true);
In order to simply optimize our WordPress installation without adding a plugin, we can define some constants that help this purpose. It is convenient to add each of the following settings independently and see their result in production, before leaving them permanently in our file wp-config.php.
WP_CACHE: Activate the WordPress object cache using the code:
define('WP_CACHE', true);
WP_HOME and WP_SITEURL: they allow you to define the routes of the website, instead of recovering them from the database.
define('WP_HOME', 'http://myweb.com'); define('WP_SITEURL', 'http://myweb.com');
To optimize the database, in a way that limits the number of posts revisions, we can use the following code, where n is the number of revisions:
define('WP_POST_REVISIONS', n);
And if you don’t want to save revisions, we can add the code:
define('WP_POST_REVISIONS',false);
As for the bin of posts, pages and comments we can indicate the emptying period, which by default is 30 days, for a different period with the following code, where n is the number of days:
define('EMPTY_TRASH_DAYS', n);
Other features that can be activated in WordPress and thus not install optimization plugins is to compress the content of certain static files (CSS and JavaScript), concatenate JavaScript and force gzip compression. This can be done using the following code
define('COMPRESS_CSS', true); define('COMPRESS_SCRIPTS', true); define('CONCATENATE_SCRIPTS', true); define('ENFORCE_GZIP', true);
In addition to the above, which is very basic, you can perform other operations that can improve the use of WordPress, and whose information can be expanded on the official WordPress.org website.