I'm playing around with a custom theme for Wordpress and I have this code snippet in my header, home and footer.php files.
<?php
//Get the Wordpress page_id and language for use in template items.
global $pg_id;
global $lang;
if ($_GET["page_id"] && is_numeric($_GET["page_id"])) {
$pg_id = $_GET["page_id"];
}
$validLang = array("en", "fr");
if ($_GET["lang"] && in_array($_GET["lang"], $validLang)) {
$lang = $_GET["lang"];
} else {
$lang = "en";
}
//echo ($lang);
//echo ($pg_id);
?>
I should have this code in one location. Where should I place it so the global variable $lang is available in the header, footer, home and other template files?