I have added the function to enqueue the script and it worked perfectly this way
wp_enqueue_script( ‘google-map’, ‘https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap‘, array(), ‘3.0’, true );
How to replace the “YOUR_API_KEY” with a variable $key.
The $key is an option in the wordpress theme options that appears properly. when I echo $key;
Please help me to get this sorted.
Read more here: Add a variable to wp_enqueue_script script url