WP_ENVIRONMENT_TYPE set to local in wp-config automatically on site start

What issue or error are you experiencing?

Somewhat recently it seems like every time I start a site on local this line of code is added automatically:
define( ‘WP_ENVIRONMENT_TYPE’, ‘local’ );

This isn’t usually an issue on sites where we’re only pushing the theme, but on Pantheon for example where the whole public folder is pushed, it has caused many issues of unintentionally declaring dev, test, and live environments as “local”.

This hasn’t always happened, but I have no idea why it’s happening or how to stop it?
Any help appreciated!


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

I’ve tested it by deleting this line of code from the wp-config.php file, it is re-added at site start on local without fail.


System Details

  • Local Version:
    Version 9.0.1+6673

  • Operating System (OS) and OS version:
    macOS 14.4.1 (23E224)


Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)

local-lightning.log (451.9 KB)

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.