Add a Google Map API Key to Advanced Custom Fields (ACF)

The Google Map field in ACF is an interactive map field featuring a search input, location finder and a draggable marker. Sometimes you may be presented with a nasty error message instead of a map. Here is how you fix it.

The error message above is displayed instead of the map field when a Google API key is missing. To fix this you first need to get a Google API key, then add it to ACF using one of the methods below.

ACF and ACF PRO

add_filter('acf/fields/google_map/api', function ($api) {

	$api['key'] = 'your-api-key';

	return $api;

});

ACF PRO

add_action('acf/init', function () {

	acf_update_setting('google_api_key', 'your-api-key');

});

Recent Articles