… from a custom WordPress page template to my child theme
You can’t. And a
global variable won’t help. The theme’s
functions.php file loads first, before any other templates load. You can’t pass variables backwards to something that has already loaded.
What I think you want to do, based on what your code appears to be trying to do, is embed your data in the template file:
wp_enqueue_script( 'extra js', get_stylesheet_directory_uri() . '/js/extra.js' ); $datatoBePassed = array( 'hvuri' => get_stylesheet_directory_uri() . '/page-homevalue.php', 'latitude' => __(latitude), 'longitude' => __(longitude) ); wp_localize_script( 'extra js', 'gmap_php_vars', $datatoBePassed );
Proof of concept:
In effect you are doing more or less the opposite of what you are trying to do.
extra.js file you enqueue.