The is_php_version_compatible() WordPress PHP function checks if the current PHP version is compatible with the specified minimum required version.
Usage
is_php_version_compatible( $required );
Example:
$is_compatible = is_php_version_compatible('7.3'); if ($is_compatible) { echo "Your PHP version is compatible."; } else { echo "Your PHP version is not compatible."; }
Parameters
$required
(string) – Minimum required PHP version to check compatibility.
More information
See WordPress Developer Resources: is_php_version_compatible()
Examples
Check compatibility with PHP 7.4
This example checks if the current PHP version is compatible with PHP 7.4.
$is_compatible = is_php_version_compatible('7.4'); if ($is_compatible) { echo "Your PHP version is compatible with 7.4."; } else { echo "Your PHP version is not compatible with 7.4."; }
Check compatibility with PHP 8.0
This example checks if the current PHP version is compatible with PHP 8.0.
$is_compatible = is_php_version_compatible('8.0'); if ($is_compatible) { echo "Your PHP version is compatible with 8.0."; } else { echo "Your PHP version is not compatible with 8.0."; }
Display a custom message based on compatibility
This example displays a custom message based on whether the current PHP version is compatible with PHP 7.2.
$is_compatible = is_php_version_compatible('7.2'); $message = $is_compatible ? "Great! Your PHP version is compatible with 7.2." : "Oops! Your PHP version is not compatible with 7.2."; echo $message;
Check compatibility with PHP 7.0 and display current PHP version
This example checks if the current PHP version is compatible with PHP 7.0 and also displays the current PHP version.
$is_compatible = is_php_version_compatible('7.0'); $current_version = phpversion(); if ($is_compatible) { echo "Your PHP version ($current_version) is compatible with 7.0."; } else { echo "Your PHP version ($current_version) is not compatible with 7.0."; }
Run a function if PHP version is compatible with a specific version
This example runs a custom function my_custom_function()
if the current PHP version is compatible with PHP 7.3.
$is_compatible = is_php_version_compatible('7.3'); if ($is_compatible) { my_custom_function(); } else { echo "Your PHP version is not compatible with 7.3."; } function my_custom_function() { echo "This is a custom function."; }