Implementing wp_get_environment_type()

After seeing that Kinsta has implemented the GET ENVIRONMENT function, I’m trying to include it in my project for the first time! :slightly_smiling_face:

I would like to wrap a snippet of code, that only shows Google Analytics, if the code is on production so that my data is not skewed.

When I add wp_get_environment_type() to my local site, it tells me it’s ‘production’ though? Should this not be indicating it is local automatically? Or am I missing a step?

Resources:

Screenshot:


Screen Shot 2022-07-19 at 3.37.16 PM

Hi @natasha_nightshift, thanks for reaching out! So that change was exclusively for MyKinsta. I do not believe the DevKinsta containers/servers contain the same fix. You can make that as a Feature Request, though!

It’s pretty easy to manipulate that value with something like this to your wp-config.php (I just quickly wrote/tested this but it’s a good starting point):

if (preg_match("/.*\.local$/", $_SERVER['HTTP_HOST'])){
	define( 'WP_ENVIRONMENT_TYPE', 'staging' );
}

That will only change the variable for the .local URL/won’t affect anything once you Push the site to Kinsta Staging or Staging to Live.

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