A set of WordPress constants to spice up your wp-config.php
file and improve your website’s performance and security.
Security
Environment
The default constant specifies the environment in which the code is executed. On some hosts, it affects behavior and error display. I prefer to define it clearly in my wp-config.php
file.
define('WP_ENVIRONMENT_TYPE', 'production');
Code language: PHP (php)
URL
Prevents the site’s domain from being changed in the admin interface.
define('WP_HOME', 'https://website.domain/');
define('WP_SITEURL', 'https://website.domain/');
Code language: PHP (php)
SSL
Forces HTTPS access to the administration interface.
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
Code language: PHP (php)
Debugging
Disables WordPress debugging functions, preventing errors from being displayed on the public site.
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);
Code language: PHP (php)
Updates
Forces automatic minor WordPress core updates and prevents new themes from being downloaded by default.
define('WP_AUTO_UPDATE_CORE', 'minor');
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', true);
Code language: PHP (php)
Database repair
Prevents access to the built-in WordPress database repair tool.
define('WP_ALLOW_REPAIR', false);
Code language: PHP (php)
Code Inclusion
Prevents uncontrolled pasting and execution of code in the editor.
⚠️ May cause issues with some plugins or themes that display SVGs.
define('DISALLOW_UNFILTERED_HTML', true);
Code language: PHP (php)
Code Editing
Prevents site files from being edited through the admin interface.
define('DISALLOW_FILE_EDIT', true);
Code language: PHP (php)
Uploads
Disables unfiltered downloads, preventing the download of potentially dangerous files.
define('ALLOW_UNFILTERED_UPLOADS', false);
Code language: PHP (php)
Performance
Cache
If set, WordPress will attempt to load the /wp-content/advanced-cache.php
file when the page loads. This enables caching plugins such as Cache Enabler.
define('WP_CACHE', true);
Code language: PHP (php)
Memory
These constants define the memory limits for the public interface (WP_MEMORY_LIMIT)
and the admin interface (WP_MAX_MEMORY_LIMIT)
. I align them as closely as possible with the memory allocated in php.ini
.
WordPress uses default values (40MB) and checks the server configuration to adjust these limits. Setting them directly avoids configuration checks and errors, optimizes hosting resource usage, and improves overall site performance.
Generally, the admin interface requires more resources.
define('WP_MAX_MEMORY_LIMIT', '128M'); // Set 256M for WooCommerce
define('WP_MEMORY_LIMIT', '40M');
Code language: PHP (php)
Compression and Concatenation
Forces the use of minified JS scripts, enables WordPress to minify styles and scripts, loads scripts in concatenated files, and enables GZIP compression.
define('SCRIPT_DEBUG', false);
define('CONCATENATE_SCRIPTS', true);
define('COMPRESS_SCRIPTS', true);
define('COMPRESS_CSS', true);
define('ENFORCE_GZIP', true);
Code language: PHP (php)
Automatic Backup
Sets automatic backup to five minutes (instead of the default one minute), reducing server load.
define('AUTOSAVE_INTERVAL', 300);
Code language: PHP (php)
WordPress Cron
Disables the native WordPress cron to prevent duplication.
⚠️ Enable only if you can configure a cron directly on your hosting.
define('DISABLE_WP_CRON', true);
Code language: PHP (php)
Bonus: Plugin Constants
Contact Form 7
By default, Contact Form 7 loads its scripts and styles on all pages. I disable this globally and include these files only on pages that need them.
define('WPCF7_LOAD_JS', false);
define('WPCF7_LOAD_CSS', false);
Code language: PHP (php)
SQLite Object Cache
Enables object caching with APCU using SQLite Object Cache.
/** Object cache **/
define('WP_SQLITE_OBJECT_CACHE_APCU', true);
Code language: PHP (php)
ZenPress
The ZenPress plugin I’m developing can be configured with WordPress constants. On blog-style sites, I keep the RSS feed functionality active.
Need more performance?
Discover ZenPress, my ultra-lightweight free plugin that removes unnecessary features and ads from your WordPress site, boosts security, and improves performance.
/** ZenPress **/
define('ZENPRESS_DISABLE_RSS', false);
Code language: PHP (php)
Full code snippet
This section is for optimizing the performance and security of a WordPress site and should be inserted in the customization part of the wp-config.php
file.
Make sure to adjust it according to your site’s needs.
/* Add any custom values between this line and the "stop editing" line. */
/* ————————————————
* Security
* ———————————————— */
define('WP_ENVIRONMENT_TYPE', 'production');
define('WP_HOME', 'https://website.domain/');
define('WP_SITEURL', 'https://website.domain/');
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);
define('WP_AUTO_UPDATE_CORE', 'minor');
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', true);
define('WP_ALLOW_REPAIR', false);
define('DISALLOW_UNFILTERED_HTML', true);
define('DISALLOW_FILE_EDIT', true);
define('ALLOW_UNFILTERED_UPLOADS', false);
/* ————————————————
* Performances
* ———————————————— */
define('WP_MEMORY_LIMIT', '40M');
define('WP_MAX_MEMORY_LIMIT', '128M');
define('AUTOSAVE_INTERVAL', 300);
define('WP_CACHE', true);
define('SCRIPT_DEBUG', false);
define('CONCATENATE_SCRIPTS', true);
define('COMPRESS_SCRIPTS', true);
define('COMPRESS_CSS', true);
define('ENFORCE_GZIP', true);
define('DISABLE_WP_CRON', true);
/* ————————————————
* Plugins
* ———————————————— */
/*** Contact form 7 ***/
define('WPCF7_LOAD_JS', false);
define('WPCF7_LOAD_CSS', false);
/*** Object cache ***/
define('WP_SQLITE_OBJECT_CACHE_APCU', true);
/*** ZenPress ***/
define('ZENPRESS_DISABLE_RSS', false);
/* That's all, stop editing! Happy publishing. */
Code language: PHP (php)
I hope this post helps. If you have questions, require support for your WordPress site, or want to contribute, feel free to contact me or leave a comment!
Sources
➡️ https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
➡️ https://wp-kama.com/1588/wordpress-constants
➡️ https://www.php.net/manual/en/ini.core.php#ini.memory-limit
➡️ https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is- necessary/
Leave a Reply