Advanced Custom Fields (ACF) and Secure Custom Fields (SCF) offer a fantastic feature: the ability to select a location using the Google Maps API. However, to use this API, you need a Google Cloud API key with the Maps JavaScript API and Geocoding API services enabled.
A common question arises: How to connect the API key to a WordPress site? The answer is below.
Setting Up the API Key
Simply copy the following code and paste it into your theme’s functions.php
file. Replace your-api-key
with your actual API key.
// Sets ACF/SCF Goolge Maps API key. add_filter( 'acf/fields/google_map/api', function ( $api ) { $api[ 'key' ] = 'your-api-key'; return $api; });