Detect a WP Engine Website with PHP
If your workflow includes writing code outside of a WP Engine website and you need a way to tell if a website is hosted on WP Engine through code, we have a function included as part of the WP Engine mu-plugin to help.
This function will tell you if a website is on a WP Engine server: is_wpe()
- Returns true
1
only if you are on a WP Engine environment. - The output of this function is a String.
"1" = true
and"0" = false
. - A boolean value is incorrect, meaning
is_wpe() === true
will always returnfalse
. - This function will not determine if an environment is Production, Development, or Staging.
When to Use is_wpe() Function
If you are developing on a local environment and you want to test whether the site you’re seeing is on WP Engine or not, you can use the following to create a testfile.php
file in the root directory of your website:
<?php
# Use WordPress functions outside of WordPress files
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require('wp-load.php');
# Ensure the function exists before running it and printing out the return value.
if (function_exists('is_wpe')) {
echo is_wpe();
} else {
echo "The function does not exist";
}
Visiting yourdomain.com/testfile.php
will then print one of the following:
1
if the site is running on a WP Engine environment0
if it is not running on a WP Engine environmentThe function does not exist
if theis_wpe()
function has not been defined in your environment (this should never be the case on a WP Engine server as long as the WP Engine mu-plugin is installed).
The value that is returned is a String value and not a number data type so make sure to use comparisons accordingly. Here is an example used in a theme template file which first sets an $is_wpe
variable to false, and then changes it to true if it detects the appropriate response from the function.
<?php
$is_wpe = false;
if (function_exists('is_wpe')) {
if ( is_wpe() === "1" ) { $is_wpe = true; }
}
echo $is_wpe ? "yes, this is a WPE server" : "no, this is not a WPE server";
?>
NEXT STEP: PHP version and upgrade guide