Reputation: 11
I am working on a WordPress site that uses the AdvancedCustomFields plugin to display Google Maps on the page. The Maps showed correctly with no errors a few months ago, but the API key is no longer being sent? Under the Network tab I can see the API request being sent with no API key.
The only change I made initially to the existing code was to update the API key from the old (presumably expired?) key to the new key.
Within #acf.php I have the following code to set the API key for the ACF map field.
function carbon_acf_init_google_maps_api_key() {
$google_maps_api_key = 'xxxxxMyAPIKeyxxxxxxxx';
acf_update_setting( 'google_api_key', $google_maps_api_key );
}
add_action( 'acf/init', 'carbon_acf_init_google_maps_api_key' );
I would expect the API key to be properly set and the Maps to display properly. Instead I see no change and the network tab of the dev console still displays an API call with no key.
Upvotes: 1
Views: 1100
Reputation: 637
I'm using, works for me.
function my_acf_google_map_api( $api ){
$api['key'] = '********************************';
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
Upvotes: 1