1. Home
  2. Wordpress
  3. Set global variable

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

#wordpress#php
// 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