WP-Mix

A fresh mix of code snippets and tutorials

WordPress Display Version Number

Here is a simple function to display the current version number for WordPress.

Update! I can’t believe I missed this: we can use bloginfo() to get the current version number: get_bloginfo('version'). Thanks to Piet B. </update>

So let’s say that you want to display the version number for your current copy of WordPress. Easy. Just add the following function to your theme’s functions.php file (or can add via plugin file):

// display current WP version number
function shapeSpace_current_version() {
	global $wp_version;
	$v = substr($wp_version, 0, 3);
	return $v;
}

Then you can display the version number virtually anywhere in your theme template, plugin settings, or wherever:

<?php echo shapeSpace_current_version(); ?>

So if the site is running WordPress version 6.4, the function will output exactly that, “6.4”. Thus you can do something like this in your theme template:

<p>Congratulations, you are running WordPress version <?php echo shapeSpace_current_version(); ?>!</p>

..which would display:

Congratulations, you are running WordPress version 6.4!

Bonus: Make it a Shortcode

The beauty of WordPress is its flexibility. For example, we can make the previous function a shortcode by adding one line after the function, like so:

// display current WP version number
function shapeSpace_current_version() {
	global $wp_version;
	$v = substr($wp_version, 0, 3);
	return $v;
} 
add_shortcode('current_version', 'shapeSpace_current_version');

So while the first function enables us to display the version number anywhere in the theme template, this second shortcode function enables us to display the version number in any Post or Page. The shortcode to use is 6.4.

Enjoy! :)

Learn more

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