Google Maps API in WordPress InvalidKeyOrUnauthorizedURLMapError
-
I am trying to add my google map to my website. However, every page that does not have the shortcode on it, loads with an error message InvalidKeyOrUnauthorizedURLMapError. I can’t find out why. I added my website as a referrer and verified my website. My javascript code isnt wrong. I don’t believe anything is wrong with my API key. I don’t believe my shortcode is working, but that comes after trying to figure out why I am getting this error message. Can anyone help?
my website: http://www.tothenationsworldwide.com
I have this code in my functions.php
add_shortcode(‘custom-map-shortcode’, ‘custom_map_shortcode_callback’);
function custom_map_shortcode_callback() {
return ‘<div id=”map” style=”height: 100%; margin: 0;padding: 0;”></div>’;
}
add_action( ‘wp_enqueue_scripts’, ‘enqueue_map_script’ );
add_action( ‘wp_head’, function(){
echo ‘<script src=”https://maps.googleapis.com/maps/api/js?key=APIKEY&signed_in=true&callback=initMap”></script>’;
});
function enqueue_map_script(){global $post;
if( is_a( $post, ‘WP_Post’ ) && has_shortcode( $post->post_content, ‘custom-map-shortcode’) ) {
wp_enqueue_script( ‘map-script’, get_template_directory_uri() . ‘/js/map_script.js’);
}}
The topic ‘Google Maps API in WordPress InvalidKeyOrUnauthorizedURLMapError’ is closed to new replies.