WordPress Constants: Powerful for Customization and Optimization

WordPress offers multiple ways to configure and customize your site, from the admin panel to hooks (filters and actions). However, one of the most powerful and often overlooked methods is through PHP constants. These constants provide developers with fine-grained control over various aspects of WordPress functionality.

You've likely encountered constants in the wp-config.php file. For instance:

// Enable debugging
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

// Customize the content directory
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/custom-content' );
define( 'WP_CONTENT_URL', 'https://example.com/custom-content' );

// Enforce SSL for admin and logins
define( 'FORCE_SSL_ADMIN', true );

// Disable automatic updates
define( 'AUTOMATIC_UPDATER_DISABLED', true );

// Increase memory limit
define( 'WP_MEMORY_LIMIT', '256M' );

These constants demonstrate the breadth of control available, from enabling debugging features to customizing core WordPress directories and enforcing security measures.

Constants in WordPress Development

Beyond configuration, constants play a vital role in WordPress development. They provide consistent, reliable ways to reference important paths, URLs, and settings within your themes and plugins. For instance:

  • ABSPATH: The absolute path to the WordPress directory
  • WPINC: The relative path to the includes directory

Using these constants ensures your code remains portable and resistant to changes in WordPress' file structure or a user's custom setup.

The Value of a Comprehensive Constants Reference

Understanding the full range of available WordPress constants can significantly enhance your ability to:

  1. Debug effectively in development environments
  2. Implement advanced security measures
  3. Optimize WordPress performance for specific hosting environments
  4. Create more robust and flexible themes and plugins

Explore the table below to discover how WordPress constants can elevate your development practices and unlock new potentials in your WordPress projects.

Drop me a tweet if there is something you think is missing here @Tmeister

ConstantDescriptionDefault ValuePossible Values
Admin
IS_PROFILE_PAGEDetermined if you are on profile edit page in admin panelNot set
true
WP_ADMINWill be defined if you are in the WordPress admin panelNot set
true
WP_BLOG_ADMINWill be defined if you are running a query in /wp-admin/Not set
true
WP_USER_ADMINDefined on pages: /wp-admin/user/Not set
true
Content Management
AUTOSAVE_INTERVALInterval of autosave posts on editing60
Time in seconds
DOING_AUTOSAVEDetermined when auto-saving a recordNot set
true
EMPTY_TRASH_DAYSNumber of days before an entry is deleted from the Recycle Bin30
Numberfalse
WP_POST_REVISIONSRevisions recordstrue
truefalseNumber
Cookies
ADMIN_COOKIE_PATHPath to directory /wp-admin/SITECOOKIEPATH wp-admin Or for Multisite subdirectory SITECOOKIEPATH
Path
AUTH_COOKIEName of authorization cookiewordpress_ COOKIEHASH
Cookie name
COOKIEHASHHash for generating cookie namesNot set
Hash
COOKIEPATHThe path to the WordPress root directoryHome URL without http(s)://
Path
COOKIE_DOMAINThe domain that will be used in setcookie() and for which cookies will be setfalse
Domain
LOGGED_IN_COOKIEName Cookie for authenticationwordpress_logged_in_ COOKIEHASH
Cookie name
PASS_COOKIECookie name for the passwordwordpresspass_ COOKIEHASH
Cookie name
PLUGINS_COOKIE_PATHPath to plugins directoryWP_PLUGIN_URL without http(s)://
Path
SECURE_AUTH_COOKIECookie name for SSL authorizationwordpress_sec_ COOKIEHASH
Cookie name
SITECOOKIEPATHThe path to the siteSite URL without http(s)://
Path
TEST_COOKIECookie name for the test cookiewordpress_test_cookie
Cookie name
USER_COOKIEThe cookie name for userswordpressuser_ COOKIEHASH
Cookie name
Core
SHORTINITStops the loading of the main part of WordPressNot set
true
Cron
ALTERNATE_WP_CRONUses an alternative Cron systemfalse
truefalse
DISABLE_WP_CRONDeactivates the cron (job scheduler) in WordPressNot set
true
DOING_CRONDetermined if cron task (scheduled task) is executedNot set
true
WP_CRON_LOCK_TIMEOUTSets the minimum time interval, between the execution of cron requests60
Seconds
Database
CUSTOM_USER_META_TABLELets you define your own "user meta" tableNot set
Table name
CUSTOM_USER_TABLEAllows you to define your own "user" tableNot set
Table name
DB_CHARSETDefines the encoding (charset) of the databaseutf8
Charset
DB_COLLATEDefines the collation type for the databaseutf8_general_ci
Collation
DB_HOSTDefines database hostlocalhost
Hostname
DB_NAMESpecifies database nameNot set
Database name
DB_PASSWORDDefines database passwordNot set
Password
DB_USERIdentifies database userNot set
Username
WP_ALLOW_REPAIRAllows automatic rebuilding and optimization of database tablesNot set
true
Debugging
DIEONDBERRORIf defined, database errors will be displayedNot set
true
ERRORLOGFILEIf defined, the database errors will be written to the log fileNot set
Path
SAVEQUERIESEnables or disables writing database queries to an arrayNot set
truefalse
SCRIPT_DEBUGEnables or disables loading of packed CSS and JavaScript filesNot set
truefalse
WP_DEBUGEnables or disables WordPress debug modefalse
truefalse
WP_DEBUG_DISPLAYEnables or disables error output to the screentrue
truefalsenull
WP_DEBUG_LOGEnables or disables error logging to file /wp-content/debug.logfalse
truefalse
WP_SANDBOX_SCRAPINGDisables fatal error handlingNot set
true
Development
WP_LOCAL_DEVNot a WordPress constant - often used to enable additional functionality when definedNot set
true
Email
WP_MAIL_INTERVALSpecifies the time interval during which only one mail request can be executed300
Seconds
Environment
WP_ENVIRONMENT_TYPEDefines the current development environmentproduction
localdevelopmentstagingproduction
File System
FS_CHMOD_DIRDefines access rights for directories0755
Octal
FS_CHMOD_FILEDefines access rights for files0644
Octal
FS_CONNECT_TIMEOUTSpecifies the timeout to create a connection30
Seconds
FS_METHODSpecifies how to connect to the file systemNot set
directsshftpextftpsockets
FS_TIMEOUTDefines timeout after a connection loss30
Seconds
FTP_BASEPath to WordPress root directoryABSPATH
Path
FTP_CONTENT_DIRDirectory path /wp-content/WP_CONTENT_DIR
Path
FTP_HOSTSpecifies a host for FTPNot set
Hostname
FTP_LANG_DIRPath to directory of language filesWP_LANG_DIR
Path
FTP_PASSSpecifies the password for FTPNot set
Password
FTP_PLUGIN_DIRPath to plugins directoryWP_PLUGIN_DIR
Path
FTP_PRIKEYSpecifies private key for SSHNot set
Path
FTP_PUBKEYSpecifies public key for SSHNot set
Path
FTP_SSHTurns SSH on or offNot set
truefalse
FTP_SSLTurns SSL on or offNot set
truefalse
FTP_USERSpecifies a username for FTPNot set
Username
UPLOADSThe path to the site-specific upload directory depends on ABSPATHUPLOADBLOGSDIR /{blogid}/files/
Path
Import
WP_IMPORTINGDefined when you are importing WordPress dataNot set
true
WP_LOAD_IMPORTERSDefined in import review in control panel (Tools -> Importer)Not set
true
Installation
WP_INSTALLINGWill be defined, during a new installation or upgradeNot set
true
WP_SETUP_CONFIGDefined during WP installation or configurationNot set
true
Localization
WP_LANG_DIRThe absolute path to the directory with the language filesWP_CONTENT_DIR . '/languages' Or ABSPATH . WPINC . '/languages'
Path
WPLANGDeprecated since WP 4.0. Defines the WordPress localization code
Language code
Maintenance
WP_REPAIRINGDefined on page: /wp-admin/maint/repair.phpNot set
true
Media
IMAGE_EDIT_OVERWRITEControls image edit behaviorNot set
truefalse
MEDIA_TRASH"Recycle Bin" functionality for media filesfalse
truefalse
Multisite
ALLOW_SUBDIRECTORY_INSTALLAllows you to install Multisite in a subdirectory (subdomain)Not set
true
BLOGUPLOADDIRThe absolute path to the "upload" directory of a particular blogWP_CONTENT_DIR /blogs.dir/{ID блога}/files/
Path
BLOG_ID_CURRENT_SITEThe blog ID of the main site1
Number
DOMAIN_CURRENT_SITEThe domain of the main sitedomain
Domain
MULTISITEWill be defined if Multi-site mode is usedNot set
true
NOBLOGREDIRECTSpecifies the site URL to which WordPress will redirect requests if the registration is closed or the site does not existNot set
URL
PATH_CURRENT_SITEThe path to the main siteNot set
Path
SITE_ID_CURRENT_SITENetwork ID of the main site1
Number
SUBDOMAIN_INSTALLDetermines whether the installation goes to a subdomain or notNot set
truefalse
SUNRISEIf defined, WordPress will upload the file /wp-content/sunrise.phpNot set
true
UPLOADBLOGSDIRThe path to the underlying upload directory, depending on ABSPATHwp-content/blogs.dir
Path
WP_ALLOW_MULTISITEIf defined, the Multi-Site feature is availableNot set
true
WP_INSTALLING_NETWORKTo be determined when installing the network or when querying the network adminNot set
true
WP_NETWORK_ADMINDefined in page: /wp-admin/network/Not set
true
WPMU_ACCEL_REDIRECTEnables or disables support for X-Sendfile Headerfalse
truefalse
WPMU_SENDFILEEnables or disables support for X-Accel-Redirect Headerfalse
truefalse
Paths
ABSPATHThe path to the WordPress root directory with a slash at the endpath to the directory with the file wp-load.php
Path
WP_CONTENT_DIRAbsolute path to wp-content directoryABSPATH/wp-content
Path
WP_CONTENT_URLURL to the wp-content directory{URL сайта}/wp-content
URL
WP_PLUGIN_DIRAbsolute path to plugins directoryWP_CONTENT_DIR . '/plugins'
Path
WP_PLUGIN_URLURL of the plugins directoryWP_CONTENT_URL . '/plugins'
URL
WP_TEMP_DIRThe absolute path to the directory for temporary filesNot set
Path
WPINCName of the directory wp-includeswp-includes
Not set
WPMU_PLUGIN_DIRThe absolute path to the directory of plugins like "Must Use Plugins"WP_CONTENT_DIR/mu-plugins
Path
WPMU_PLUGIN_URLURL of the plugins directory of type "Must Use Plugins"WP_CONTENT_URL /mu-plugins
URL
Performance
COMPRESS_CSSEnables/disables stylesheet compression (stylesheets)Not set
truefalse
COMPRESS_SCRIPTSEnables / disables compression of JavaScript filesNot set
truefalse
CONCATENATE_SCRIPTSEnables/disables compression of JavaScript or CSS files before compressionNot set
truefalse
ENFORCE_GZIPEnables/disables gzip compressionNot set
truefalse
WP_CACHEIf defined, WordPress will try to load the /wp-content/advanced-cache.php filefalse
truefalse
WP_MAX_MEMORY_LIMITMaximum memory limit for some WordPress features256M
Memory size
WP_MEMORY_LIMITMemory limit for running WordPress scripts32M, For Multisite 64M
Memory size
WP_START_TIMESTAMPWP code start time stampNot set
Timestamp
Plugins
WP_UNINSTALL_PLUGINDefined during plugin removalNot set
true
Proxy
WP_PROXY_BYPASS_HOSTSAllows you to define which addresses should not connect through the proxyNot set
Comma-separated list
WP_PROXY_HOSTDefines proxy addressNot set
IP address or domain
WP_PROXY_PASSWORDDefines password for the proxyNot set
Password
WP_PROXY_PORTDefines port for the proxyNot set
Port number
WP_PROXY_USERNAMEDefines proxy usernameNot set
Username
Request Types
APP_REQUESTDetermined when an Atom Publishing Protocol request is madeNot set
true
DOING_AJAXDetermined when an AJAX request is executedNot set
true
IFRAME_REQUESTDetermined if IFRAME request is executedNot set
true
REST_REQUESTDefined when performing a REST requestNot set
true
XMLRPC_REQUESTDefined at any XML-RPC requestNot set
true
Security
SECURE_AUTH_KEYSecret keyNot set
Text key
SECURE_AUTH_SALTSecret keyNot set
Text key
WP_ACCESSIBLE_HOSTSIf WP_HTTP_BLOCK_EXTERNAL is defined, you can add hosts that will not be blocked (white list)Not set
Comma-separated list
WP_HTTP_BLOCK_EXTERNALAllows blocking external requestsNot set
truefalse
Site Configuration
WP_HOMEThe URL of your WordPress blogNot set
URL
WP_SITEURLThe URL of the WordPress root directory where the WordPress files are locatedNot set
URL
Template
COMMENTS_TEMPLATEDetermined when a comment template is loadedNot set
true
Testing
WP_TESTS_CONFIG_FILE_PATHLocation of the wp-tests-config.php file which is used for PHPUnit testsNot set
Path
Theme
BACKGROUND_IMAGEDefines the default background imageNot set
Image URL
HEADER_IMAGEDefines the default header imageNot set
Image URL
HEADER_IMAGE_HEIGHTSpecifies the height of the header imageNot set
Number
HEADER_IMAGE_WIDTHDefines the width of the header imageNot set
Number
HEADER_TEXTCOLORDetermines the color of the header textNot set
Color code
NO_HEADER_TEXTEnables or disables support for header textNot set
truefalse
STYLESHEETPATHContains the absolute path to the theme folderNot set
Path
TEMPLATEPATHContains an absolute path from the root of the site to the current themeNot set
Path
WP_DEFAULT_THEMESets the default theme for new sitestwentyeleven
Theme name
WP_USE_THEMESEnables or disables theme loadingNot set
truefalse
Updates
AUTOMATIC_UPDATER_DISABLEDAuto-update engine, introduced in version 3.7false
truefalse
CORE_UPGRADE_SKIP_NEW_BUNDLEDAffect new file groups (plugins or themes) when updatingNot set
truefalse
WP_AUTO_UPDATE_COREManages core auto-updatesminor
truefalseminor