REST API & Developer PHP Beginner

Set the Environment Type for Staging Sites

Tell WordPress and plugins whether a site is production, staging, development or local, so they can behave differently.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 2 lines
// One of: 'production', 'staging', 'development', 'local'.
define( 'WP_ENVIRONMENT_TYPE', 'staging' );

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

Staging sites should never send real emails, ping search engines or take payments. WordPress has a built-in way to say which kind of site this is, and many plugins and snippets check it.

How it works

wp_get_environment_type() returns the value of WP_ENVIRONMENT_TYPE, or 'production' when it isn’t set. Code can then check it, for example if ( 'production' !== wp_get_environment_type() ) { … }.

WordPress itself treats 'local' and 'development' as development sites, and Site Health shows the value.

Things to watch

  • Set it in wp-config.php on each copy of the site. Don’t copy the staging wp-config.php to production.
  • Pairs with “Show the Environment in the Admin Bar” so everyone can see which site they’re on.

How to test it

Go to Tools → Site Health → Info → WordPress Constants. WP_ENVIRONMENT_TYPE should show your value.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only