WordPress at Your Fingertips

WordPress Constants

WordPress is configurable in the admin panel or using hooks (filters, events), and WordPress can also be configured using PHP constants.

You've probably used constants more than once in the wp-config.php file, for example:

define( 'WPLANG', 'ru_RU' );          // specify the localization file;
define( 'EMPTY_TRASH_DAYS', false );  // turn off the recycle garbage can;
define( 'WP_POST_REVISIONS', false ); // disable record revisions;
define( 'DISABLE_WP_CRON', true );    // disable cron;
define( 'AUTOSAVE_INTERVAL', 120 );   // increase the autosave interval;
// etc.

Constants can also be very useful when writing plugins. For example, when you want to get the path to the plugins directory, you can use the constant WP_PLUGIN_DIR, and to get the URL to the plugins directory, you can use the constant WP_PLUGIN_URL. This is handy because some users may change the plugins directory by specifying the constant WP_PLUGIN_DIR, and your plugin will not work if you specify an absolute path without using the constant.

There are many ways to use constants and having a complete list of them at your fingertips is handy.

This post is most of the constants that WordPress uses. The list will be continually updated. If you suddenly have something to add to the list or you haven't found a constant here that you know about, please write in the comments.

Contents:

Basic

WP_AUTO_UPDATE_CORE

Manages core auto-updates:

  • true - enable all updates - developer versions, minor and major releases.
  • false - Disable all core updates - developer versions, minor and major releases.
  • 'minor' - enable updates only for minor releases (within a branch).

Can be: true | false | 'minor'

AUTOMATIC_UPDATER_DISABLED

Auto-update engine, introduced in version 3.7. The default constant is undefined (false - auto-update enabled). To disable auto-update, set this constant to true:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

Can be: true | false

AUTOSAVE_INTERVAL
Interval of autosave posts on editing.
Can be: time in seconds
Default: 60
CORE_UPGRADE_SKIP_NEW_BUNDLED
true - affect new file groups (plugins or themes) when updating.
Can be: true | false
DISABLE_WP_CRON
Deactivates the cron (job scheduler) in WordPress.
Can be: true
EMPTY_TRASH_DAYS
Number of days before an entry (page, attachment, post, comment, etc.) is deleted from the Recycle Bin. Put false in wp-config.php, if you want to disable Recycle Bin, posts will be deleted when deleted irretrievably.
Can be: number of days
Default: 30
IMAGE_EDIT_OVERWRITE
false - new images will be created when editing - copies of the original. true - the old image will be overwritten.
Can be: true | false
MEDIA_TRASH
"Recycle Bin" functionality for media files. true - the Recycle Bin works. false - it does not work.
Can be: true | false
Default: false
WPLANG
Defines the WordPress localization code. Full list of codes see here. Needed to translate the site into the desired language.
Can be: ru_RU
WP_DEFAULT_THEME
Sets the default theme for new sites. And is used as a fallback for broken WordPress themes.
Can be: theme name
Default: twentyeleven
WP_CRON_LOCK_TIMEOUT
Sets the minimum time interval, between the execution of cron requests. Since version 3.3.
Can be: time in seconds
Default: 60
WP_MAIL_INTERVAL
Specifies the time interval during which only one mail request can be executed.
Can be: time in seconds
Default: 300
WP_POST_REVISIONS

Revisions records:

  • true - enabled
  • false - disabled
  • число - number of record revisions. 5 - the record will contain a maximum of 5 revisions.

Can be: true | false | number in numbers
Default: true

WP_MAX_MEMORY_LIMIT
Maximum memory limit for some WordPress features.
Default: 256M
WP_MEMORY_LIMIT
Memory limit for running WordPress scripts.
Default: 32M, For Multisite 64M

Statuses

APP_REQUEST
Determined when an Atom Publishing Protocol request is made.
Can be: true
COMMENTS_TEMPLATE
Determined when a comment template is loaded.
Can be: true
DOING_AJAX
Determined when an AJAX request is executed.
Can be: true
DOING_AUTOSAVE
Determined when auto-saving a record.
Can be: true
DOING_CRON
Determined if cron task (scheduled task) is executed.
Can be: true
IFRAME_REQUEST
Determined if IFRAME request is executed.
Can be: true
IS_PROFILE_PAGE
Determined if you are on profile edit page in admin panel.
Can be: true
REST_REQUEST
Defined when performing a REST request.
Can be: true
SHORTINIT
true - stops the loading of the main part of WordPress. Can be used if only basic functions are needed. Connection to the database will already be set ($wpdb will be defined). Filters are also, already defined. The constant is called in the wp-settings.php file. Reed more about SHORTINIT.
Can be: true
WP_ADMIN
Will be defined if you are in the WordPress admin panel.
Can be: true
WP_BLOG_ADMIN
Will be defined if you are running a query in /wp-admin/.
Can be: true
WP_IMPORTING
Defined when you are importing WordPress data.
Can be: true
WP_INSTALLING
Will be defined, during a new installation or upgrade.
Can be: true
WP_INSTALLING_NETWORK
To be determined when installing the network or when querying the network admin. Since version 3.3. Before that it was: WP_NETWORK_ADMIN_PAGE.
Can be: true
WP_LOAD_IMPORTERS
Defined in import review in control panel (Tools -> Importer).
Can be: true
WP_NETWORK_ADMIN
Defined in page: /wp-admin/network/.
Can be: true
WP_REPAIRING
Defined on page: /wp-admin/maint/repair.php.
Can be: true
WP_SETUP_CONFIG
Defined during WP installation or configuration.
Can be: true
WP_UNINSTALL_PLUGIN

Defined during plugin removal. To uninstall a plugin, create a file uninstall.php in its folder, when uninstalling triggers code from this file, so that there are no surprises in this file should be checked for the existence of WP_UNINSTALL_PLUGIN constant - it must be defined at the time of uninstalling the plugin.

An example of checking:

if( ! defined('WP_UNINSTALL_PLUGIN') exit();
// code for removing the plugin's presence on the site

Can be: true

WP_USER_ADMIN
Defined on pages: /wp-admin/user/.
Can be: true
XMLRPC_REQUEST
Defined at any XML-RPC request.
Can be: true

Пути, каталоги, ссылки

ABSPATH
The path to the WordPress root directory with a slash at the end. The path will be from the root of the server, for example: C:/sites/wptest.ru/www/.
Default: path to the directory with the file wp-load.php
WPINC
Name of the directory wp-includes. This constant cannot be changed.
Default: wp-includes
WP_LANG_DIR
The absolute path to the directory with the language files.
Default: WP_CONTENT_DIR . '/languages' Or ABSPATH . WPINC . '/languages'
WP_PLUGIN_DIR
Absolute path to plugins directory.
Default: WP_CONTENT_DIR . '/plugins'
WP_PLUGIN_URL
URL of the plugins directory.
Default: WP_CONTENT_URL . '/plugins'
WP_CONTENT_DIR
Absolute path [to wp-content directory].(/handbook/wordpress/papka-wp-content). Example: C:/sites/wptest.ru/www/wp-content
Default: ABSPATH/wp-content
WP_CONTENT_URL
URL to the wp-content directory. For example: http://example.com/wp-content.
Default: {URL сайта}/wp-content
WP_HOME
The URL of your WordPress blog. If you set this constant in wp-config.php, then users will not be able to accidentally change the address of the blog in settings: settings->main. Also, it is useful if WordPress files lie in a subdirectory, then the blog address will be WP_HOME - http://yourdomain.comand the address to that blog's directory would be WP_SITEURL - http://yourdomain.com/blog.
WP_SITEURL
The URL of the WordPress root directory where the WordPress files are located.
WP_TEMP_DIR
The absolute path to the directory for temporary files. Usually such files are written when plugins and the engine are updated.
WPMU_PLUGIN_DIR

The absolute path to the directory of plugins like «Must Use Plugins». For example: C:/sites/wptest.ru/www/wp-content/mu-plugins.

Default: WP_CONTENT_DIR/mu-plugins

WPMU_PLUGIN_URL
URL of the plugins directory of type «Must Use Plugins»
Default: WP_CONTENT_URL /mu-plugins

Database

DB_CHARSET
Defines the encoding (charset) of the database.
Can be: see documentation MySQL
Default: utf8
DB_COLLATE
Defines the collation type for the database.
Can be: see documentation MySQL
Default: utf8_general_ci
DB_HOST
Defines database host.
Can be: IP address, domain and/or port
Default: localhost
DB_NAME
Specifies database name.
Can be: database name
DB_PASSWORD
Defines database password.
Can be: password for the database
DB_USER
Identifies database user.
Can be: user name
WP_ALLOW_REPAIR
Allows automatic rebuilding and optimization of database tables using /wp-admin/maint/repair.php.
Can be: true
CUSTOM_USER_TABLE
Allows you to define your own "user" table.
Can be: имя таблицы
CUSTOM_USER_META_TABLE
Lets you define your own "user meta" table.
Can be: table name

Template

BACKGROUND_IMAGE
Defines the default background image.
HEADER_IMAGE
Defines the default header image.
HEADER_IMAGE_HEIGHT
Specifies the height of the header image.
HEADER_IMAGE_WIDTH
Defines the width of the header image.
HEADER_TEXTCOLOR
Determines the color of the header text.
NO_HEADER_TEXT
Enables or disables support for header text.
Can be: true | false
STYLESHEETPATH
Specifies the absolute path to the theme folder, which is the folder where the current parent or child theme's stylesheet file is located. It does not contain a trailing slash. See also. get_stylesheet_directory().
TEMPLATEPATH
Specifies an absolute path from the root of the site to the current theme (parent, not child). Does not contain a slash at the end. See "Theme Loading". get_template_directory().
WP_USE_THEMES
Enables or disables theme loading.
Can be: true | false

File system and connections

FS_CHMOD_DIR
Defines access rights for directories. Defined only in the admin area when connecting a file wp-admin/includes/file.php.
Can be: see documentation PHP
Default: 0755
FS_CHMOD_FILE
Defines access rights for files. Defined only in admin area when connecting a file wp-admin/includes/file.php.
Can be: See PHP documenetation
Default: 0644
FS_CONNECT_TIMEOUT
Specifies the timeout to create a connection.
Can be: timeout in seconds
Default: 30
FS_METHOD
Specifies how to connect to the file system.
Can be: direct | ssh | ftpext | ftpsockets
FS_TIMEOUT
Defines timeout after a connection loss.
Can be: time in seconds
Default: 30
FTP_BASE
Path to WordPress root directory.
Default: ABSPATH
FTP_CONTENT_DIR
Directory path /wp-content/.
Default: WP_CONTENT_DIR
FTP_HOST
Specifies a host for FTP.
Can be: IP address, domain, and/or port
FTP_LANG_DIR
Path to directory of language files.
Default: WP_LANG_DIR
FTP_PASS
Specifies the password for FTP.
FTP_PLUGIN_DIR
Path to plugins directory.
Default: WP_PLUGIN_DIR
FTP_PRIKEY
Specifies private key for SSH.
FTP_PUBKEY
Specifies public key for SSH.
FTP_SSH
Turns SSH on or off.
Can be: true | false
FTP_SSL
Turns SSL on or off.
Can be: true | false
FTP_USER
Specifies a username for FTP.
WP_PROXY_BYPASS_HOSTS
Allows you to define which addresses should not connect through the proxy.
Can be: www.somesite.net, `.somesite.org`*
WP_PROXY_HOST
Defines proxy address.
Can be: IP адрес или домен
WP_PROXY_PASSWORD
Defines password for the proxy.
WP_PROXY_PORT
Defines port for the proxy.
WP_PROXY_USERNAME
Defines proxy username.
WP_HTTP_BLOCK_EXTERNAL
Allows blocking external requests.
Can be: true | false
WP_ACCESSIBLE_HOSTS
If WP_HTTP_BLOCK_EXTERNAL is defined, you can add hosts that will not be blocked (white list).
Can be: `www.somesite.net, .somesite.org`*

Debugging (bug finding).

WP_LOCAL_DEV

The default constant is not used anywhere in the core, but is intended as a general standard to enable, for example, some additional functionality when this constant is defined.

Example of connecting different databases and setting this constant, if the site is developed locally. The code must be added to wp-config.php. Also on the local must create a file local-config.php and add to it the local data connection to the database. Also, in this case, somewhere else in the code you can use the constant WP_LOCAL_DEV to check whether we are on the local or working site.

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
include( dirname( __FILE__ ) . '/local-config.php' );
  define( 'WP_LOCAL_DEV', true ); // We'll talk about this later
}
else {
  define( 'DB_NAME',     'production_db'       );
  define( 'DB_USER',     'production_user'     );
  define( 'DB_PASSWORD', 'production_password' );
  define( 'DB_HOST',     'production_db_host'  );
}

Read more here.

menu
WP_START_TIMESTAMP
WP code start time stamp - set as microtime( true ) at the moment of early file connection wp-includes/default-constants.php. Introduced in WP 5.2.
SAVEQUERIES

Enables or disables writing database queries to an array ($wpdb->queries).

Add the following code to the file wp-config.php:

define( 'SAVEQUERIES', true );

Then in your theme's footer.php, insert the code that outputs all queries:

if ( current_user_can( 'administrator' ) ) {
	global $wpdb;
	echo "<pre>";
	print_r( $wpdb->queries );
	echo "</pre>";
}

Can be: true | false

SCRIPT_DEBUG
Enables or disables loading of packed CSS and JavaScript files.
Can be: true | false
WP_DEBUG
Enables or disables WordPress debug mode. Read more about WP_DEBUG
Can be: true | false
Default: false
WP_DEBUG_DISPLAY
Enables or disables error output to the screen.
Can be: true | false | null
Default: true
WP_DEBUG_LOG
Enables or disables error logging to file /wp-content/debug.log
Can be: true | false
Default: false
WP_TESTS_CONFIG_FILE_PATH

Location of the wp-tests-config.php file which is used for PHPUnit tests. Example definition in file phpunit.xml:

<phpunit ...
	<php>
		<const name="WP_TESTS_CONFIG_FILE_PATH" value="/path/to/wp-tests-config.php" />
	</php>
</phpunit>

Script caching and compression

WP_CACHE
If defined, WordPres will try to load the /wp-content/advanced-cache.php file when the page loads.
Can be: true | false
Default: false
COMPRESS_CSS
Enables/disables stylesheet compression (stylesheets).
Can be: true | false
COMPRESS_SCRIPTS
Enables / disables compression of JavaScript files.
Can be: true | false
CONCATENATE_SCRIPTS

Enables/disables compression of JavaScript or CSS files before compression.

Note: all JS files will be merged into one to speed up admin panel loading. If you don't have Javascript working in the admin panel, you can try to disable this feature by adding this code to wp-config.php:

define( 'CONCATENATE_SCRIPTS', false );

Can be: true | false

ENFORCE_GZIP
Enables/disables gzip compression
Can be: true | false

Protection and cookies

ADMIN_COOKIE_PATH
Path to directory /wp-admin/.
Default: SITECOOKIEPATH wp-admin Or for Multisite subdirectory ``SITECOOKIEPATH```
ALLOW_UNFILTERED_UPLOADS
Enables unfiltered file uploads, by a user with the unfiltered_upload right. Enables the unfiltered_upload right to work. If you did not enable this constant, users with the unfiltered_upload permission will not be filtered. current_user_can('unfiltered_upload').
Can be: true
AUTH_COOKIE
Name of authorization cookie.
Default: wordpress_ COOKIEHASH
AUTH_KEY
Secret key.
Can be: text key
AUTH_SALT
Secret key additive.
Can be: text key
COOKIEHASH
Hash for generating cookie names.
COOKIEPATH
The path to the WordPress root directory.
Default: Home URL without http(s)://
COOKIE_DOMAIN
The domain that will be used in setcookie() and for which cookies will be set. The default is the current domain, you can specify a specific domain, for example .site.ru, then the cookie will be valid for the domain site.ru and all subdomains: foo.site.ru, bar.site.ru
Default: false, and for MU builds .site.ru, where site.ru is the main domain of the network of sites.
CUSTOM_TAGS
Allows you to override the list of HTML security labels. View in: /wp-includes/kses.php.
Can be: true | false
Default: false
DISALLOW_FILE_EDIT
Allows you to prohibit editing themes and plugins using the WordPress editor.
Can be: true
DISALLOW_FILE_MODS

Prohibits any editing of files in the WordPress file system (except the directory for downloads wp-content/uploads):

define( 'DISALLOW_FILE_MODS', true );

Please note that by setting this directive you will no longer be able to install and update themes and plugins via the admin panel. You'll have to do it manually via FTP or SSH. The value of the constant can be overridden through the filter file_mod_allowed.

Can be: true

DISALLOW_UNFILTERED_HTML

Allows you to disable unfiltered HTML for all users, including the admin. Some privileges can be disabled at the level of
configuration file wp-config.php, for example you can disable all users (including admins and network admins) to publish unfiltered HTML using:

define( 'DISALLOW_UNFILTERED_HTML', true );

Can be: true

FORCE_SSL_ADMIN
Activates SSL for the admin and control panel.
Can be: true | false
Default: false
FORCE_SSL_LOGIN
Activates SSL for the login page.
Can be: true | false
Default: false
LOGGED_IN_COOKIE
Name Cookie for authentication.
Default: wordpress_logged_in_ COOKIEHASH
LOGGED_IN_KEY
Secret key.
Can be: text key
LOGGED_IN_SALT
The secret key.
Can be: text key
NONCE_KEY
The secret key.
Can be: text key
NONCE_SALT
Secret Key.
Can be: text key
PASS_COOKIE
Cookie name for the password.
Default: wordpresspass_ COOKIEHASH
PLUGINS_COOKIE_PATH
Path to plugins directory.
Default: WP_PLUGIN_URL без http(s)://
SECURE_AUTH_COOKIE
Cookie name for SSL authorization.
Default: wordpress_sec_ COOKIEHASH
SECURE_AUTH_KEY
Secret key.
Can be: text key
SECURE_AUTH_SALT
Secret key.
Can be: text key
SITECOOKIEPATH
The path to the site.
Default: Site URL without http(s)://
TEST_COOKIE
Cookie name for the test cookie.
Default: wordpress_test_cookie
USER_COOKIE
The cookie name for users.
Default: wordpressuser_ COOKIEHASH

Multisites

ALLOW_SUBDIRECTORY_INSTALL
Allows you to install Multisite in a subdirectory (subdomain).
Can be: true
BLOGUPLOADDIR
The absolute path to the "upload" directory of a particular blog.
Default: WP_CONTENT_DIR /blogs.dir/{ID блога}/files/
BLOG_ID_CURRENT_SITE
The blog ID of the main site.
Default: 1
DOMAIN_CURRENT_SITE
The domain of the main site.
Default: domain
DIEONDBERROR
If defined, database errors will be displayed.
Can be: true
ERRORLOGFILE
If defined, the database errors will be written to the log file.
Can be: Absolute path to the file with write access
MULTISITE
Will be defined if Multi-site mode is used.
Can be: true
NOBLOGREDIRECT
Specifies the site URL to which WordPress will redirect requests if the registration is closed or the site does not exist.
Can be: %siteurl% For the main site or a specific URL
PATH_CURRENT_SITE
The path to the main site.
UPLOADBLOGSDIR
The path to the underlying upload directory, depending on ABSPATH.
Default: wp-content/blogs.dir
SITE_ID_CURRENT_SITE
Network ID of the main site.
Default: 1
SUBDOMAIN_INSTALL
Determines whether the installation goes to a subdomain or not.
Can be: true | false
SUNRISE
If defined, WordPres will upload the file /wp-content/sunrise.php.
Can be: true
UPLOADS
The path to the site-specific upload directory depends on ABSPATH.
Default: UPLOADBLOGSDIR /{blogid}/files/
WPMU_ACCEL_REDIRECT
Enables or disables support for X-Sendfile Header.
Can be: true | false
Default: false
WPMU_SENDFILE
Enables or disables support for X-Accel-Redirect Header.
Can be: true | false
Default: false
WP_ALLOW_MULTISITE
If defined, the Multi-Site feature is available (Tools -> Network Setup).
Can be: true

Time constants

These constants are made for convenience when you want to set the time interval in seconds:

MINUTE_IN_SECONDS
Minute in seconds - 60
HOUR_IN_SECONDS
Hour in seconds - 60*60
DAY_IN_SECONDS
Day (day) in seconds - 60*60*24
WEEK_IN_SECONDS
Week in seconds - 60*60*24*7
YEAR_IN_SECONDS
Year in seconds - 60*60*24*365
No comments
    Log In