Code Snippet: Get WordPress Version


You can’t assume everyone is running the latest version of WordPress, especially around big point releases.

Simple Version Check

If you want your code to be backwards compatible (keep it within reason), you can do a simple WordPress version check with conditionals by using:


Or just use the global variable $wp_version.

For instance, to check if the user had WordPress 3.1 installed, you could do something like this:

global $wp_version;
if ( $wp_version >= 3.1 ) {
     // run some code

More reference is here:

Use a Function

If you are referencing this multiple times, you may want to set it up as a function. Austin Passy recommends this:

if ( ! function_exists( 'is_version' ) ) {
	function is_version( $version = '3.1' ) {
		global $wp_version;
		if ( version_compare( $wp_version, $version, '>=' ) ) {
			return false;
		return true;

You can read about version compare at

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

More notes about this in the codex.

About Devin

I'm a WordPress developer based in Austin, Texas. Follow my projects on GitHub, or more general WordPress ramblings as @devinsays on twitter.

6 thoughts on “Code Snippet: Get WordPress Version

  1. The Frosty wrote:

    I actually use this function:

    if ( ! function_exists( ‘is_version’ ) ) {
    function is_version( $version = ’3.0′ ) {
    global $wp_version;

    if ( version_compare( $wp_version, $version, ‘<' ) ) {
    return false;
    return true;

    • Devin wrote:

      Cool. I added it to the post. Any reason to use this over the basic check?

  2. The Frosty wrote:

    No not really. Just easier for me to create the function and call is_version() throughout the plugin or theme files.

  3. Mark wrote:

    Or you can check the $wp_version variable – the get_bloginfo(‘version’) function simply returns this variable.

    • Devin wrote:

      Good point! I updated the post a bit.

  4. littleguy wrote:

    Thanks for this. Here is my function that checks if WP is at least at a specific version ($version). Useful if you want to enable some features only for newer versions of WP.

    * Checks if WordPress is at least at version $version
    * @param $version
    * @return bool
    function wordpress_is_at_least_version($version)
    if (version_compare($version, get_bloginfo('version'), '>=' ))
    return true;
    return false;

    if(wordpress_is_at_least_version(’3.8′)) { //do something };

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>