Discover in this tutorial how to define a development, staging or testing environment in WordPress using code.
One of the new features of WordPress 5.5 is that it incorporates the option to define a development environment.
This option is great because it allows you to differentiate between installations that are in production or that you use for testing.
In fact, you can choose between three environments:
- Production (default)
The nice thing about this is that it opens the door to use different configurations depending on the environment.
Let’s see how you can define it:
Snippet to define an environment type in WordPress
Add the following code somewhere before the line that contains “require_once (ABSPATH…” In the wp-config.php file:
In this case, you’re indicating that it’s a development environment but you could use the other one supported by default, staging.
You can also create a custom environment with the name you want (for example, ‘test’). To do this add this to the wp-config.php:
Once defined you can use the
wp_get_environment_type() function to get different behaviors depending on the environment.
Now you know how to define the environment type of your WordPress installation (production, development, staging…).
This opens the door for you to create functions that only run in a certain environment.
For example? Enable or disable plugins depending on the environment.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂