You can’t assume everyone is running the latest version of WordPress. If your plugin or theme code relies on specific WordPress features (especially newer ones), you may need to check the which version of WordPress the site is running on.
Simple Version Check
There are two ways to get the WordPress version:
get_bloginfo( 'version' );
Or, with the global variable $wp_version:
global $wp_version;
For instance, to check if the site has WordPress 4.3 or later installed, you could use this:
global $wp_version;
if ( version_compare( $wp_version, '4.3', '>=' ) ) {
// WordPress version is greater than 4.3
}
More reference is here: http://codex.wordpress.org/Function_Reference/get_bloginfo
Use a function
If you’re needing to compare WordPress versions multiple times in your plugin, you may want to consider using a small function:
/*
* Compares the version of WordPress running to the $version specified.
*
* @param string $operator
* @param string $version
* @returns boolean
*/
function is_version( $operator = '>', $version = '4.0' ) {
global $wp_version;
return version_compare( $wp_version, $version, $operator );
}
Use function_exists
Another easy way to find the version is to check for a function that was introduced after a certain release. For instance, post formats were introduced in 3.1. So to see if it 3.1 or higher you could use something like:
if ( function_exists( 'has_post_format' ) ) {
// 3.1 specific code
}