The is_wp_version_compatible() WordPress PHP function checks if the current WordPress version is compatible with the specified required version.
Usage
is_wp_version_compatible( $required )
Input: is_wp_version_compatible( '5.2' )
Output: true
if the current WordPress version is 5.2 or higher, false
otherwise.
Parameters
$required
(string) – Minimum required WordPress version.
More information
See WordPress Developer Resources: is_wp_version_compatible()
Examples
Check compatibility with WordPress 5.7
This example checks if the current WordPress version is compatible with version 5.7.
if ( is_wp_version_compatible( '5.7' ) ) { // Your plugin or theme is compatible with the current WordPress version. } else { // Your plugin or theme is not compatible with the current WordPress version. }
Check compatibility with WordPress 4.9
This example checks if the current WordPress version is compatible with version 4.9.
if ( is_wp_version_compatible( '4.9' ) ) { // Your plugin or theme is compatible with the current WordPress version. } else { // Your plugin or theme is not compatible with the current WordPress version. }
Display a message if not compatible with WordPress 5.0
This example displays a warning message if the current WordPress version is not compatible with version 5.0.
if ( ! is_wp_version_compatible( '5.0' ) ) { echo "Your plugin or theme is not compatible with the current WordPress version. Please update WordPress."; }
Deactivate a plugin if not compatible with WordPress 5.3
This example deactivates a plugin if the current WordPress version is not compatible with version 5.3.
if ( ! is_wp_version_compatible( '5.3' ) ) { deactivate_plugins( plugin_basename( __FILE__ ) ); }
Load a fallback file if not compatible with WordPress 5.5
This example loads a fallback file if the current WordPress version is not compatible with version 5.5.
if ( is_wp_version_compatible( '5.5' ) ) { require_once 'advanced-feature.php'; } else { require_once 'fallback-feature.php'; }