Title: Write environment-specific code
Author: WordPress VIP Documentation
Published: September 29, 2020
Last modified: February 10, 2026

---

 1. [Infrastructure](https://docs.wpvip.com/infrastructure/)
 2. [VIP Platform environments](https://docs.wpvip.com/infrastructure/environments/)
 3. Write environment-specific code

#  Write environment-specific code

The VIP Platform’s `VIP_GO_APP_ENVIRONMENT` constant and the [WordPress function `wp_get_environment_type()`](https://developer.wordpress.org/reference/functions/wp_get_environment_type/)
can both be used to customize environment-specific behavior in code.

For example, a conditional statement could be used to set a variable with a different
value depending on if the code is running on a production, development, or local
environment. The VIP Platform constant and the WordPress function each return different
values but can be used in a similar way.

## `VIP_GO_APP_ENVIRONMENT`

The `VIP_GO_APP_ENVIRONMENT` constant can be used to conditionally run code based
on the environment type to which the code has been deployed. This is populated as
early as `vip-config.php`.

The `VIP_GO_APP_ENVIRONMENT` constant is defined by the `type` value of an environment.
At a minimum, every VIP application has a `production` environment type. The application
might have additional environment types such as `develop`, `staging`, or `preprod`.

The `type` value for each of an application’s environments can be retrieved with
[the VIP-CLI command `vip app [APP_NAME]`](https://docs.wpvip.com/vip-cli/commands/app/).
Output from the command will include values for the application ID, environment 
ID, environment name, and the environment’s deploying branch.

In this code example, `VIP_GO_APP_ENVIRONMENT` is used to restrict code to run only
on the `production` environment:

    ```lang-php
    if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && 'production' === VIP_GO_APP_ENVIRONMENT ) {
        // Run this only on production
    } 
    ```

In this code example, code is restricted from running on the `production` and `preprod`
environments:

    ```lang-php
    $disallowed_envs = array( 'production', 'preprod' );
    if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && ! in_array( VIP_GO_APP_ENVIRONMENT, $disallowed_envs, true ) ) {
        // Run this code in all environments except prodution and preprod.
    }
    ```

### Use `VIP_GO_APP_ENVIRONMENT` in local environments

 * By default, `VIP_GO_APP_ENVIRONMENT` is already defined as `local` in a [VIP Local Development Environment](https://docs.wpvip.com/vip-local-development-environment/).
 * For [other local development applications](https://docs.wpvip.com/local-development/)(
   e.g., VVV, Laravel) the `VIP_GO_APP_ENVIRONMENT` constant is not pre-defined.
   To use the constant, define it as `local` in `wp-config.php` (e.g., `define( '
   VIP_GO_APP_ENVIRONMENT', 'local' );` ).
 * N**ever define `VIP_GO_APP_ENVIRONMENT` in [`vip-config.php`](https://docs.wpvip.com/wordpress-skeleton/vip-config-directory/)
   or anywhere in the application code.** It is already defined by the VIP Platform.
   If the code is committed and deployed it will cause PHP warnings in the logs:`
   Warning: Constant VIP_GO_APP_ENVIRONMENT already defined...`.

## `wp_get_environment_type()`

The [WordPress function `wp_get_environment_type()`](https://developer.wordpress.org/reference/functions/wp_get_environment_type/)
can be used to write environment-specific code in plugins or themes. `wp_get_environment_type()`
can only be used after WordPress has fully loaded. As a result, it will not work
as expected if added to `vip-config.php`, which loads _before_ WordPress.

Unlike the value set in `VIP_GO_APP_ENVIRONMENT`, the output of `wp_get_environment_type()`
is limited to four possible values: production, development, staging, and local.
The VIP Platform sets the return value of `wp_get_environment_type()` based on the
following mapping of common VIP Platform environment names:

| VIP Platform environment type | `wp_get_environment_type()` return value | 
| production | production | 
| develop,
development | development | 
| local  | local | 
| any other custom name(preprod, staging, testing, uat, etc.) | staging |

## Additional VIP Platform constants

Additional constants that are set by the VIP Platform with per-environment values—
before `vip-config.php` is run—can be used to customize environment-specific behavior.

The constant name and its platform-set values are as follows:

 * `VIP_GO_APP_BRANCH`: The Git branch deploying to the environment (e.g., `production`,`
   production-built`, `develop-built`)
 * `VIP_GO_APP_ID`: The environment’s unique numeric ID (e.g. `1234`). For example,
   a production application (parent) may have `VIP_GO_APP_ID` of `1234`, but a non-
   production environment (child) may have a `VIP_GO_APP_ID` of `3006`.

**Note**

 * As a best practice, code should always check that a constant is defined before
   using it, for example: `if ( defined( 'VIP_GO_APP_ID' ) ) { …`
 * These constants are **not** defined in a [VIP Local Development Environment](https://docs.wpvip.com/vip-local-development-environment/).

Last updated: February 10, 2026