Answer the question
In order to leave comments, you need to log in
How to set a variable whose value can be displayed anywhere on the site?
Tell me how to set a single variable, the value of which can be displayed anywhere on the site (header.php, footer.php, etc.)?
If I specify this in functions.php, for example, as $city = 'Москва';
, and then call in header.php echo $city;
, then empty space is displayed.
Answer the question
In order to leave comments, you need to log in
Instead of $city use $GLOBALS['city'], the $GLOBALS variable is available everywhere.
Singleton
But it is not correct.
Use a common class for the entire site.
Or settings in xml, gradle and the like
Another option is to useupdate_option()
$city_data = array(
'iso-area' => 'RU-MOS',
'title' => 'Москва',
'gde' => 'в Москве',
'kuda' => 'в Москву',
'otkuda' => 'из Москвы',
'chej' => 'Московский',
'chego' => 'Москвы',
'chemu' => 'Москве',
'o-chem' => 'о Москве',
'english' => 'Moscow',
'population' => '12 655 050',
'region' => 'central',
);
update_option( '_city_data', $city_data, 'yes' );
$site_data = get_option( '_site_data' );
vardump( $site_data['title'] );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question