WP-Mix

A fresh mix of code snippets and tutorials

WordPress Check PHP Version

When working with the WP API, you may need to check the current version of PHP to ensure compatibility.

if (version_compare(PHP_VERSION, '5.6', '<')) {
	wp_die('PHP 5.6 or better is required.');
}

This code snippet uses PHP’s version_compare() function and predefined PHP_VERSION constant. You can use this technique in any WordPress theme or plugin to determine whether or not the current version of PHP meets current WordPress minimum requirements (currently PHP v5.6). See references below.

References

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress