Get WordPress Version with PHP

We needed to get the WordPress version with PHP code and we found a global WordPress variable that you can use to access that. All of WordPress’ global variables can be found at https://codex.wordpress.org/Global_Variables.

In order to access the current WordPress version, you need to add the following to your function:

global $wp_version;

Then, you can reference that variable later on in the function and it’ll throw you the current WordPress version:

echo 'WordPress Version'.$wp_version;

Here’s what the full function would look like:

public function example_function(){
    global $wp_version;
    echo 'WordPress Version'.$wp_version;

If you need to access several WordPress global variables, check out our post on accessing multiple global variables in a function.

Leave a Reply

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