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 directoryWPINC
: 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:
- Debug effectively in development environments
- Implement advanced security measures
- Optimize WordPress performance for specific hosting environments
- 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
Constant | Description | Default Value | Possible Values | |
---|---|---|---|---|
Admin | ||||
IS_PROFILE_PAGE | Determined if you are on profile edit page in admin panel | Not set | true | |
WP_ADMIN | Will be defined if you are in the WordPress admin panel | Not set | true | |
WP_BLOG_ADMIN | Will be defined if you are running a query in /wp-admin/ | Not set | true | |
WP_USER_ADMIN | Defined on pages: /wp-admin/user/ | Not set | true | |
Content Management | ||||
AUTOSAVE_INTERVAL | Interval of autosave posts on editing | 60 | Time in seconds | |
DOING_AUTOSAVE | Determined when auto-saving a record | Not set | true | |
EMPTY_TRASH_DAYS | Number of days before an entry is deleted from the Recycle Bin | 30 | Numberfalse | |
WP_POST_REVISIONS | Revisions records | true | truefalseNumber | |
Cookies | ||||
ADMIN_COOKIE_PATH | Path to directory /wp-admin/ | SITECOOKIEPATH wp-admin Or for Multisite subdirectory SITECOOKIEPATH | Path | |
AUTH_COOKIE | Name of authorization cookie | wordpress_ COOKIEHASH | Cookie name | |
COOKIEHASH | Hash for generating cookie names | Not set | Hash | |
COOKIEPATH | The path to the WordPress root directory | Home URL without http(s):// | Path | |
COOKIE_DOMAIN | The domain that will be used in setcookie() and for which cookies will be set | false | Domain | |
LOGGED_IN_COOKIE | Name Cookie for authentication | wordpress_logged_in_ COOKIEHASH | Cookie name | |
PASS_COOKIE | Cookie name for the password | wordpresspass_ COOKIEHASH | Cookie name | |
PLUGINS_COOKIE_PATH | Path to plugins directory | WP_PLUGIN_URL without http(s):// | Path | |
SECURE_AUTH_COOKIE | Cookie name for SSL authorization | wordpress_sec_ COOKIEHASH | Cookie name | |
SITECOOKIEPATH | The path to the site | Site URL without http(s):// | Path | |
TEST_COOKIE | Cookie name for the test cookie | wordpress_test_cookie | Cookie name | |
USER_COOKIE | The cookie name for users | wordpressuser_ COOKIEHASH | Cookie name | |
Core | ||||
SHORTINIT | Stops the loading of the main part of WordPress | Not set | true | |
Cron | ||||
ALTERNATE_WP_CRON | Uses an alternative Cron system | false | truefalse | |
DISABLE_WP_CRON | Deactivates the cron (job scheduler) in WordPress | Not set | true | |
DOING_CRON | Determined if cron task (scheduled task) is executed | Not set | true | |
WP_CRON_LOCK_TIMEOUT | Sets the minimum time interval, between the execution of cron requests | 60 | Seconds | |
Database | ||||
CUSTOM_USER_META_TABLE | Lets you define your own "user meta" table | Not set | Table name | |
CUSTOM_USER_TABLE | Allows you to define your own "user" table | Not set | Table name | |
DB_CHARSET | Defines the encoding (charset) of the database | utf8 | Charset | |
DB_COLLATE | Defines the collation type for the database | utf8_general_ci | Collation | |
DB_HOST | Defines database host | localhost | Hostname | |
DB_NAME | Specifies database name | Not set | Database name | |
DB_PASSWORD | Defines database password | Not set | Password | |
DB_USER | Identifies database user | Not set | Username | |
WP_ALLOW_REPAIR | Allows automatic rebuilding and optimization of database tables | Not set | true | |
Debugging | ||||
DIEONDBERROR | If defined, database errors will be displayed | Not set | true | |
ERRORLOGFILE | If defined, the database errors will be written to the log file | Not set | Path | |
SAVEQUERIES | Enables or disables writing database queries to an array | Not set | truefalse | |
SCRIPT_DEBUG | Enables or disables loading of packed CSS and JavaScript files | Not set | truefalse | |
WP_DEBUG | Enables or disables WordPress debug mode | false | truefalse | |
WP_DEBUG_DISPLAY | Enables or disables error output to the screen | true | truefalsenull | |
WP_DEBUG_LOG | Enables or disables error logging to file /wp-content/debug.log | false | truefalse | |
WP_SANDBOX_SCRAPING | Disables fatal error handling | Not set | true | |
Development | ||||
WP_LOCAL_DEV | Not a WordPress constant - often used to enable additional functionality when defined | Not set | true | |
WP_MAIL_INTERVAL | Specifies the time interval during which only one mail request can be executed | 300 | Seconds | |
Environment | ||||
WP_ENVIRONMENT_TYPE | Defines the current development environment | production | localdevelopmentstagingproduction | |
File System | ||||
FS_CHMOD_DIR | Defines access rights for directories | 0755 | Octal | |
FS_CHMOD_FILE | Defines access rights for files | 0644 | Octal | |
FS_CONNECT_TIMEOUT | Specifies the timeout to create a connection | 30 | Seconds | |
FS_METHOD | Specifies how to connect to the file system | Not set | directsshftpextftpsockets | |
FS_TIMEOUT | Defines timeout after a connection loss | 30 | Seconds | |
FTP_BASE | Path to WordPress root directory | ABSPATH | Path | |
FTP_CONTENT_DIR | Directory path /wp-content/ | WP_CONTENT_DIR | Path | |
FTP_HOST | Specifies a host for FTP | Not set | Hostname | |
FTP_LANG_DIR | Path to directory of language files | WP_LANG_DIR | Path | |
FTP_PASS | Specifies the password for FTP | Not set | Password | |
FTP_PLUGIN_DIR | Path to plugins directory | WP_PLUGIN_DIR | Path | |
FTP_PRIKEY | Specifies private key for SSH | Not set | Path | |
FTP_PUBKEY | Specifies public key for SSH | Not set | Path | |
FTP_SSH | Turns SSH on or off | Not set | truefalse | |
FTP_SSL | Turns SSL on or off | Not set | truefalse | |
FTP_USER | Specifies a username for FTP | Not set | Username | |
UPLOADS | The path to the site-specific upload directory depends on ABSPATH | UPLOADBLOGSDIR /{blogid}/files/ | Path | |
Import | ||||
WP_IMPORTING | Defined when you are importing WordPress data | Not set | true | |
WP_LOAD_IMPORTERS | Defined in import review in control panel (Tools -> Importer) | Not set | true | |
Installation | ||||
WP_INSTALLING | Will be defined, during a new installation or upgrade | Not set | true | |
WP_SETUP_CONFIG | Defined during WP installation or configuration | Not set | true | |
Localization | ||||
WP_LANG_DIR | The absolute path to the directory with the language files | WP_CONTENT_DIR . '/languages' Or ABSPATH . WPINC . '/languages' | Path | |
WPLANG | Deprecated since WP 4.0. Defines the WordPress localization code | Language code | ||
Maintenance | ||||
WP_REPAIRING | Defined on page: /wp-admin/maint/repair.php | Not set | true | |
Media | ||||
IMAGE_EDIT_OVERWRITE | Controls image edit behavior | Not set | truefalse | |
MEDIA_TRASH | "Recycle Bin" functionality for media files | false | truefalse | |
Multisite | ||||
ALLOW_SUBDIRECTORY_INSTALL | Allows you to install Multisite in a subdirectory (subdomain) | Not set | true | |
BLOGUPLOADDIR | The absolute path to the "upload" directory of a particular blog | WP_CONTENT_DIR /blogs.dir/{ID блога}/files/ | Path | |
BLOG_ID_CURRENT_SITE | The blog ID of the main site | 1 | Number | |
DOMAIN_CURRENT_SITE | The domain of the main site | domain | Domain | |
MULTISITE | Will be defined if Multi-site mode is used | Not set | true | |
NOBLOGREDIRECT | Specifies the site URL to which WordPress will redirect requests if the registration is closed or the site does not exist | Not set | URL | |
PATH_CURRENT_SITE | The path to the main site | Not set | Path | |
SITE_ID_CURRENT_SITE | Network ID of the main site | 1 | Number | |
SUBDOMAIN_INSTALL | Determines whether the installation goes to a subdomain or not | Not set | truefalse | |
SUNRISE | If defined, WordPress will upload the file /wp-content/sunrise.php | Not set | true | |
UPLOADBLOGSDIR | The path to the underlying upload directory, depending on ABSPATH | wp-content/blogs.dir | Path | |
WP_ALLOW_MULTISITE | If defined, the Multi-Site feature is available | Not set | true | |
WP_INSTALLING_NETWORK | To be determined when installing the network or when querying the network admin | Not set | true | |
WP_NETWORK_ADMIN | Defined in page: /wp-admin/network/ | Not set | true | |
WPMU_ACCEL_REDIRECT | Enables or disables support for X-Sendfile Header | false | truefalse | |
WPMU_SENDFILE | Enables or disables support for X-Accel-Redirect Header | false | truefalse | |
Paths | ||||
ABSPATH | The path to the WordPress root directory with a slash at the end | path to the directory with the file wp-load.php | Path | |
WP_CONTENT_DIR | Absolute path to wp-content directory | ABSPATH/wp-content | Path | |
WP_CONTENT_URL | URL to the wp-content directory | {URL сайта}/wp-content | URL | |
WP_PLUGIN_DIR | Absolute path to plugins directory | WP_CONTENT_DIR . '/plugins' | Path | |
WP_PLUGIN_URL | URL of the plugins directory | WP_CONTENT_URL . '/plugins' | URL | |
WP_TEMP_DIR | The absolute path to the directory for temporary files | Not set | Path | |
WPINC | Name of the directory wp-includes | wp-includes | Not set | |
WPMU_PLUGIN_DIR | The absolute path to the directory of plugins like "Must Use Plugins" | WP_CONTENT_DIR/mu-plugins | Path | |
WPMU_PLUGIN_URL | URL of the plugins directory of type "Must Use Plugins" | WP_CONTENT_URL /mu-plugins | URL | |
Performance | ||||
COMPRESS_CSS | Enables/disables stylesheet compression (stylesheets) | Not set | truefalse | |
COMPRESS_SCRIPTS | Enables / disables compression of JavaScript files | Not set | truefalse | |
CONCATENATE_SCRIPTS | Enables/disables compression of JavaScript or CSS files before compression | Not set | truefalse | |
ENFORCE_GZIP | Enables/disables gzip compression | Not set | truefalse | |
WP_CACHE | If defined, WordPress will try to load the /wp-content/advanced-cache.php file | false | truefalse | |
WP_MAX_MEMORY_LIMIT | Maximum memory limit for some WordPress features | 256M | Memory size | |
WP_MEMORY_LIMIT | Memory limit for running WordPress scripts | 32M, For Multisite 64M | Memory size | |
WP_START_TIMESTAMP | WP code start time stamp | Not set | Timestamp | |
Plugins | ||||
WP_UNINSTALL_PLUGIN | Defined during plugin removal | Not set | true | |
Proxy | ||||
WP_PROXY_BYPASS_HOSTS | Allows you to define which addresses should not connect through the proxy | Not set | Comma-separated list | |
WP_PROXY_HOST | Defines proxy address | Not set | IP address or domain | |
WP_PROXY_PASSWORD | Defines password for the proxy | Not set | Password | |
WP_PROXY_PORT | Defines port for the proxy | Not set | Port number | |
WP_PROXY_USERNAME | Defines proxy username | Not set | Username | |
Request Types | ||||
APP_REQUEST | Determined when an Atom Publishing Protocol request is made | Not set | true | |
DOING_AJAX | Determined when an AJAX request is executed | Not set | true | |
IFRAME_REQUEST | Determined if IFRAME request is executed | Not set | true | |
REST_REQUEST | Defined when performing a REST request | Not set | true | |
XMLRPC_REQUEST | Defined at any XML-RPC request | Not set | true | |
Security | ||||
SECURE_AUTH_KEY | Secret key | Not set | Text key | |
SECURE_AUTH_SALT | Secret key | Not set | Text key | |
WP_ACCESSIBLE_HOSTS | If 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_EXTERNAL | Allows blocking external requests | Not set | truefalse | |
Site Configuration | ||||
WP_HOME | The URL of your WordPress blog | Not set | URL | |
WP_SITEURL | The URL of the WordPress root directory where the WordPress files are located | Not set | URL | |
Template | ||||
COMMENTS_TEMPLATE | Determined when a comment template is loaded | Not set | true | |
Testing | ||||
WP_TESTS_CONFIG_FILE_PATH | Location of the wp-tests-config.php file which is used for PHPUnit tests | Not set | Path | |
Theme | ||||
BACKGROUND_IMAGE | Defines the default background image | Not set | Image URL | |
HEADER_IMAGE | Defines the default header image | Not set | Image URL | |
HEADER_IMAGE_HEIGHT | Specifies the height of the header image | Not set | Number | |
HEADER_IMAGE_WIDTH | Defines the width of the header image | Not set | Number | |
HEADER_TEXTCOLOR | Determines the color of the header text | Not set | Color code | |
NO_HEADER_TEXT | Enables or disables support for header text | Not set | truefalse | |
STYLESHEETPATH | Contains the absolute path to the theme folder | Not set | Path | |
TEMPLATEPATH | Contains an absolute path from the root of the site to the current theme | Not set | Path | |
WP_DEFAULT_THEME | Sets the default theme for new sites | twentyeleven | Theme name | |
WP_USE_THEMES | Enables or disables theme loading | Not set | truefalse | |
Updates | ||||
AUTOMATIC_UPDATER_DISABLED | Auto-update engine, introduced in version 3.7 | false | truefalse | |
CORE_UPGRADE_SKIP_NEW_BUNDLED | Affect new file groups (plugins or themes) when updating | Not set | truefalse | |
WP_AUTO_UPDATE_CORE | Manages core auto-updates | minor | truefalseminor |