1. Home
  2. Wordpress
  3. Set global variable
#wordpress#php

Set a global variable as part of the functions.php file.

// Add this function in function.php file

function set_some_global_variable() {
    global $some_variable;
    $some_variable = 1;
}
add_action( 'after_setup_theme', 'set_some_global_variable' );

// Than, it can be used in other parts of the theme

global $some_variable;

echo $some_variable;
copy
Full Wordpress cheatsheet
Sitemap Git repository