Environment Type
WordPress 5.5 introduced the WP_ENVIRONMENT_TYPE constant, allowing you to specify the current environment for your site. This helps developers and administrators distinguish between local, development, staging, and production environments, enabling environment-specific configurations and behaviors.
Why Use WP_ENVIRONMENT_TYPE?
Section titled “Why Use WP_ENVIRONMENT_TYPE?”- Environment Awareness: Easily identify which environment your site is running in (e.g., local, staging, production).
- Conditional Logic: Enable or disable features, plugins, or code based on the environment type.
- Improved Safety: Prevent accidental changes or deployments to production by restricting actions in non-production environments.
Supported Environment Types
Section titled “Supported Environment Types”WordPress recognizes the following values for WP_ENVIRONMENT_TYPE:
localdevelopmentstagingproduction
How to Set the Environment Type
Section titled “How to Set the Environment Type”Editing wp-config.php
Section titled “Editing wp-config.php”- Open your site’s
wp-config.phpfile (located in the WordPress root directory). - Add the following line above the comment
/* That's all, stop editing! Happy publishing. */:define( 'WP_ENVIRONMENT_TYPE', 'environment_type' ); - Replace
'environment_type'with one of the supported values (local,development,staging,production). - Save and close the file.
Using WP-CLI
Section titled “Using WP-CLI”If you use WP-CLI, you can set the environment type with:
wp config set WP_ENVIRONMENT_TYPE 'environment_type'Replace 'environment_type' with your desired value. Note: This command will only work if WP_ENVIRONMENT_TYPE is not already defined in wp-config.php. If it is, you must edit the file manually.
Displaying the Environment Type
Section titled “Displaying the Environment Type”Many themes and plugins can display the current environment type in the WordPress admin toolbar or dashboard, helping you quickly verify which environment you’re working in.