I need to initialize some variables in various templates (index, single, page) such as banner image of that page. But then use that value in the 'get_header()' template. A good example of this is the og_image that's usually in the header.php set of meta tags inside the head of the HTML. This image is the visual moniker for any given template page. So the best place to get this info is in the context of the main loop of that template. However the og_image tag itself is not inside that template (such as single.php) but inside the header.php.
Setting a variable to "global" inside single.php doesn't help because these are not just straight includes as in regular Php. They are somehow more wordpress specific.
The other option could be to do some black magic inside functions.php, but for something this straightforward, I would prefer not to overdo some function. Is there an easier way or best practice to share variables' values across headed and footer and sidebar?