Skip to content

Instantly share code, notes, and snippets.

@azizultex
Created January 4, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azizultex/69a43fa1217791340bc937769bd8adcd to your computer and use it in GitHub Desktop.
Save azizultex/69a43fa1217791340bc937769bd8adcd to your computer and use it in GitHub Desktop.
Google Map API for WordPress Site
function escaperoom_googlemap_api_key($url, $original_url, $_context) {
$key = 'AIzaSyAWQTIcIfpsttvugW18F1y14p8gbFXmtXE'; // your map api key
// If no key added no point in checking
if ( ! $key ) {
return $url;
}
if ( strstr( $url, "maps.google.com/maps/api/js" ) !== false || strstr( $url, "maps.googleapis.com/maps/api/js" ) !== false ) {// it's a Google maps url
if ( strstr( $url, "key=" ) === false ) {// it needs a key
$url = add_query_arg( 'key', $key, $url );
$url = str_replace( "&", "&", $url ); // or $url = $original_url
}
}
return $url;
}
add_filter( 'clean_url', 'escaperoom_googlemap_api_key', 99, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment