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 numeric.
1 == true
and0 == 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. These will all simply return
is_wpe()===1
or true. To determine an Environment name or Environment by type (Prod, Dev, Stage), try the WP Engine API.
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).
NEXT STEP: PHP version and upgrade guide