I'm having trouble printing a variable in my template of the body. The variable is set in the header.php and the page loads both header.php and template.php. This is the code in the header.php with the variable:
<?php
// Post is PAGE
$post = get_post();
$page_id = get_the_ID($post);
// echo $page_id." - ";
$page_parent_id = wp_get_post_parent_id($page_id);
if($page_parent_id==0) { $page_parent_id = $page_id; }
switch($page_parent_id) {
case 24:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradeditorino.png";
$home_url = "/torino";
break;
case 27:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradedimilano.png";
$home_url = "/milano";
break;
case 29:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradedigenova.png";
$home_url = "/genova";
break;
case 34:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradediroma.png";
$home_url = "/roma";
break;
case 42030:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradedinapoli.png";
$home_url = "/napoli";
break;
case 50629:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradediparma.png";
$home_url = "/parma";
break;
case 52120:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradediverona.png";
$home_url = "/verona";
break;
default:
$logo_url = esc_url($theme_settings['logo']);
$home_url = "/";
}
// Post is POST of CATEGORY
$post_parent = array();
$category = get_the_category();
// FIX - TANDU - BEGIN
if ( ! empty( $category ) ) { // New
if ( count($category) > 1 ) {
$post_parent = get_ancestors($category[0]->term_id,'category');
$post_parent = array_reverse($post_parent);
} else {
$post_parent[0] = $category[0]->cat_ID;
}
} // New
// FIX - TANDU - END
$post_parent = array_reverse($post_parent);
// print_r($post_parent);
switch($post_parent[0]) {
case 4:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradeditorino.png";
$home_url = "/torino";
break;
case 12:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradedimilano.png";
$home_url = "/milano";
break;
case 18:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradedigenova.png";
$home_url = "/genova";
break;
case 222:
$logo_url = "/wp-content/uploads/2019/03/logo-lestradediroma.png";
$home_url = "/roma";
break;
case 419:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradediparma.png";
$home_url = "/parma";
break;
case 386:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradediverona.png";
$home_url = "/verona";
break;
case 385:
$logo_url = "/wp-content/uploads/2022/07/logo-lestradedinapoli.png";
$home_url = "/napoli";
break;
}
?>
In the template.php this is my code:
<?php echo $home_url; ?>
I need the $home_url variable to be printable in the any template of my site. How can i do it?
I tried to print the variable and other variables from my header in my body template but doesn't work.