You’re right that Local defines the environment type if it’s not already present, @bhinchliffe.
People usually exclude their wp-config.php
during deploys so they are not pushed to production, because the production wp-config will often need different values to the local one to connect to production databases and more.
But if you need to override the value anyway, here’s how:
How do you change the ‘local’ value that Local sets?
You can override the value of WP_ENVIRONMENT_TYPE
that Local sets in a couple of ways:
Option 1
Edit your wp-config.php
and change the WP_ENVIRONMENT_TYPE
to any of the supported values, such as production
. This might be fine for sites where you don’t need the environment type to be set to ‘local’ during local development.
define( 'WP_ENVIRONMENT_TYPE', 'production' );
Local will see that the value is already set and won’t change it. (It only adds the environment type if it’s not set already.)
Option 2
You can alternatively replace the define( 'WP_ENVIRONMENT_TYPE', 'local' );
in your wp-config.php
with some logic that sets the WP_ENVIRONMENT_TYPE
conditionally. You can have it use ‘local’ when running locally and ‘production’ or ‘staging’ when it’s deployed.
For example, Pantheon offers a PANTHEON_ENVIRONMENT variable, so your logic in wp-config.php
could look something like this (untested since I don’t have a Pantheon account):
if ( defined( 'PANTHEON_ENVIRONMENT' ) ) {
if ( PANTHEON_ENVIRONMENT === 'live' ) {
define( 'WP_ENVIRONMENT_TYPE', 'production' );
} else {
define( 'WP_ENVIRONMENT_TYPE', 'staging' );
}
} else {
define( 'WP_ENVIRONMENT_TYPE', 'local' );
}
If you’re pushing your wp-config.php
to production you’ll probably want to apply similar conditional logic to other settings (such as database name and username) if those differ in your environments.
Why does Local set WP_ENVIRONMENT_TYPE
in the first place?
For anyone reading who’s curious, Local adds define( 'WP_ENVIRONMENT_TYPE', 'local' );
to wp-config.php
if it’s not already defined because otherwise WordPress defaults to the production
environment type.
Using ‘production’ when developing locally can have negative side effects for plugins that process payments or send emails, particularly if you’re working locally with a database that contains production data. Good plugins will behave differently if they detect that you’re running in a ‘local’ environment, for example by not processing subscription payments with live payment gateways.